Expand description
Retrieval-augmented generation over any text search.
Port of .NET’s TextSearchProvider (Microsoft.Agents.AI) and Go’s
agent/textsearch (v0.2.0). TextSearchProvider is a
ContextProvider wrapping a search function you supply — a vector
store query, a web search, a keyword index — and puts its results in
front of the model in one of two ways (TextSearchBehavior):
- Before each run (the default): the run’s input text is searched and
the formatted results are added as a
usermessage ahead of it. - On demand: the model gets a
Searchtool and calls it when it wants to.
With TextSearchProvider::with_recent_message_memory, the search input
also carries the last few messages of the conversation, kept in the
session’s state, so a follow-up such as “and the second one?” is
searched with the question it follows.
use agent_framework_core::text_search::{TextSearchProvider, TextSearchResult};
let provider = TextSearchProvider::new(|query: String| async move {
// Look `query` up in your index.
Ok(vec![TextSearchResult::new("Returns are accepted within 30 days.")
.with_source("Returns policy", "https://example.com/returns")])
});§Divergences
- No message filters. Upstream filters the search and storage input so history and other providers’ messages are not searched or remembered. A Rust provider only ever receives the run’s own input and response, so there is nothing to filter out.
- Logging. Result counts and failures go to
tracing; the query and formatted results are logged (attrace) only afterTextSearchProvider::with_sensitive_logging, in place of upstream’s redactor.
Structs§
- Text
Search Provider - A
ContextProviderthat adds text-search results to a run. See the module docs. - Text
Search Result - One search hit.
Enums§
- Text
Search Behavior - When a
TextSearchProvidersearches.
Constants§
- DEFAULT_
TEXT_ SEARCH_ STATE_ KEY - The default session-state key for recent-message memory.