Skip to content

knowledge

robotsix_llmio.clients.knowledge

Direct-HTTP knowledge-store client and pydantic-ai tool adapter.

Provides KnowledgeClient (async REST client for a knowledge-store API) and build_knowledge_tools(client) which wraps it into pydantic-ai- compatible async tool functions.

Imports are deferred via :pep:562 __getattr__ so that importing the knowledge package does not eagerly pull in pydantic-ai until a name is accessed.

KnowledgeClientError

Bases: RobotsixLLMIOError

Error from the knowledge-store client (HTTP, auth, malformed response).

KnowledgeClient

Bases: BaseHttpClient

Async HTTP client for a knowledge-store REST API.

Connects directly to the knowledge-store HTTP API — no agent-comm broker intermediary. Creates a fresh, timeout-bounded httpx2.AsyncClient per request (stateless per-call pattern).

Parameters

base_url: Root URL of the knowledge-store API (e.g. http://knowledge:8000/api/v1). api_key: Optional bearer token sent as Authorization: Bearer <api_key>.

search async

search(query, top_k=10)

Full-text search the knowledge store.

Parameters

query: Free-text search query. top_k: Maximum number of results to return (default 10).

Returns

list[dict] A list of result dicts, each with keys id, title, snippet, and score. An empty list means no matches.

get_document async

get_document(doc_id)

Retrieve a single document by its identifier.

Parameters

doc_id: The document identifier.

Returns

dict The document with keys id, title, content, and metadata.

Raises

KnowledgeClientError If the document is not found (HTTP 404) or the request fails.

build_knowledge_tools

build_knowledge_tools(client)

Build pydantic-ai-compatible async tool functions from a :class:KnowledgeClient.

Returns two async tool functions:

  • search_knowledge(query: str) -> str — full-text search, returns formatted results.
  • get_knowledge_document(doc_id: str) -> str — retrieve a document by ID, returns the document content.

Each tool handles its own errors and returns a plain-text message so the agent can interpret the result directly.