retrieve • AI Agent SDK

retrieve: Retrieve context from knowledge without LLM generation.

retrieve

Method

</div>

This is a method of the Agent class in the agent module.

Retrieve context from knowledge without LLM generation.

Returns a ContextPack that can be passed to chat_with_context(). This enables conditional retrieval – only retrieve when needed.

Signature

python
def retrieve(query: str) -> 'ContextPack'

Parameters

ParamField str

Search query **kwargs: Additional arguments (top_k, rerank, etc.)

Returns

ResponseField 'ContextPack'

ContextPack with context string and citations (no LLM call)

Exceptions

ValueError

If no knowledge is configured

ImportError

If RAG module is not available

Usage

python
agent = Agent(knowledge=["docs/"], retrieval_config={"citations": True})
    context = agent.retrieve("What are the key findings?")
    print(f"Found {len(context.citations)} sources")
    response = agent.chat_with_context("Summarize", context)

Uses

  • ValueError
  • ImportError
  • kwargs.setdefault
  • retrieve

Used By

Source

View on GitHub

praisonaiagents/agent/agent.py at line 6824