Architecture¶
The toolkit separates high-level agent orchestration from provider-specific implementations.
Main layers¶
- Agent layer (
doc_processing_toolkit.agent.*)- Entrypoint:
Agent(direct constructor) andAgentBuilder(fluent builder pattern) - Tool loading, media transformation, provider routing, session support, cost aggregation
session,media_policyandhistory_conversion: the session envelope (to_json/from_json), what a save does with media (inline, aMediaStore, or stripped), and the neutral representation that carries a stored history across providers
- Entrypoint:
- Provider layer (
doc_processing_toolkit.providers.*)- Provider-specific API calls for function calling and structured output
- MCP server layer (
doc_processing_toolkit.mcp_servers.*)- Three FastMCP servers:
agent_factory(meta-agent workflows and A2A sessions),docs_server(documentation search/retrieval), andmultimedia_server(TTS/STT/image tools, which write their output to files and return paths, never base64)
- Three FastMCP servers:
- Media layer (
doc_processing_toolkit.multimedia,doc_processing_toolkit.realtime)multimedia: one-shot speech synthesis, transcription, and image generation/editing, plus speech streamed as it is generated (synthesize_speech_stream/asynthesize_speech_stream)image_session: serialisable multi-turn image generation and editing on OpenAI and Googleaudio_convert: optional speech-to-text container transcoding, with a discovered (never required) ffmpegrealtime: provider-neutral speech-to-speech sessions over OpenAI Realtime and Gemini Liverealtime_translation,realtime_gpt_live: two further session families that register their own adapters into the same(provider, session_kind)routing table- Both sit beside the agent layer rather than inside it — they call providers directly and are not part of the tool-calling loop
- Core utilities (
doc_processing_toolkit.utils,data/model_information.json)- Client initialization, model metadata, token/cost helpers, and the one retry layer (tenacity
over SDK clients built with
max_retries=0)
- Client initialization, model metadata, token/cost helpers, and the one retry layer (tenacity
over SDK clients built with
Runtime flow (high level)¶
- Build
Agentwith model, instructions, and optional tools. - Detect provider from model metadata.
- Initialize provider client (
initialize_clientsorinitialize_async_clients). - Route to function-calling or structured-output execution path.
- Convert provider response to
AgentResult.

Figure: agent lifecycle and session manager.

Figure: provider router decision flow.