KnowledgeClient

KnowledgeClient is accessed via ctx.knowledge. It provides hybrid search, NL2SQL, and structured retrieval against the agent's registered knowledge bases.

Methods

query

Natural language query — returns the best answer with citations.

results: SearchResults = ctx.knowledge.query(
    question="Which invoices are overdue by more than 30 days?",
    kb="finance-kb",        # optional — defaults to agent's primary KB
    top_k=5,                # optional — number of results
)

Returns a SearchResults object.

search

Lower-level hybrid search returning ranked chunks.

results = ctx.knowledge.search(
    query="vendor payment terms",
    kb="finance-kb",
    top_k=10,
    filters={"vendor_id": "V-001"},
)

sql

Execute a natural language to SQL query against a structured source.

result = ctx.knowledge.sql(
    question="Total invoice amount by vendor this month",
    source="invoices-gold",
)
# result.sql — the generated SQL
# result.rows — list of dicts

Return types

See Types for SearchResults, SearchResult, Citation, and QueryMetadata.