query • AI Agent SDK

query: Query knowledge and get a structured answer with citations.

query

Method

</div>

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

Query knowledge and get a structured answer with citations.

This is the recommended method for getting answers with source citations. Returns a structured result with answer, citations, context used, and metadata.

Signature

python
def query(question: str) -> 'RAGResult'

Parameters

ParamField str

The question to answer **kwargs: Additional arguments (top_k, rerank, etc.)

Returns

ResponseField 'RAGResult'

RAGResult with answer, citations, context_used, and metadata

Exceptions

ValueError

If no knowledge is configured

ImportError

If RAG module is not available

Usage

python
agent = Agent(knowledge=["doc.pdf"], retrieval_config={"citations": True})
    result = agent.query("What is the main finding?")
    print(result.answer)
    for citation in result.citations:
        print(f"  [{citation.id}] {citation.source}")

Uses

  • ValueError
  • ImportError
  • kwargs.setdefault
  • query

Used By

Source

View on GitHub

praisonaiagents/agent/agent.py at line 6859