agora.fleet.llm_adapter
Model-agnostic LLM adapter.
Defines LLMProtocol — a small async interface covering tool-calling chat
completion. The backend seam has one live implementation, OllamaAdapter
(local Ollama daemon); tests inject a fake. Other backends are re-added through
the bench pipeline with evidence, not kept as dead code.
The protocol intentionally does not handle tool execution — that lives in
agora.fleet.agent_runtime. Each adapter only ferries messages and tool-call
intents between the model and the runtime, and knows how to shape its own
provider-specific assistant-turn and tool-result messages.
Non-blocking invariant: all IO is async/await with explicit timeouts.
Functions
|
Route a model string to an adapter. |
Classes
Minimal async interface every backend must satisfy. |
|
One assistant turn from the underlying model. |
|
Ollama HTTP adapter. |
|
One tool invocation in an assistant turn. |
- class agora.fleet.llm_adapter.ToolCall[source]
Bases:
objectOne tool invocation in an assistant turn.
idis the provider-assigned identifier the runtime echoes back in the tool-result message.namematches a registered inner tool;argumentsis the parsed JSON object the model emitted.- __init__(id, name, arguments)
- class agora.fleet.llm_adapter.LLMResponse[source]
Bases:
objectOne assistant turn from the underlying model.
contentis the plaintext component (often empty when the turn is pure tool-use).tool_callsare the tool invocations the runtime will execute and feed results back for.usagecarries provider token counters (input/output).stop_reasonis the termination signal, propagated so callers can distinguish budget exhaustion from natural completion.- __init__(content, tool_calls=(), usage=<factory>, stop_reason='', thinking='')
- class agora.fleet.llm_adapter.LLMProtocol[source]
Bases:
ProtocolMinimal async interface every backend must satisfy.
Adapters know how to ferry messages and tool-call intents between the model and the runtime, and how to shape their own provider-specific assistant-turn and tool-result message bodies. Tool execution is not part of this protocol — that lives in
agora.fleet.agent_runtime. The one production implementation isOllamaAdapter; tests inject a fake.- __init__(*args, **kwargs)
- class agora.fleet.llm_adapter.OllamaAdapter[source]
Bases:
objectOllama HTTP adapter. Talks to a local or remote Ollama daemon.
Uses Ollama’s OpenAI-style
role: toolmessages for tool results instead of atool_resultblock-array shape — many local models refuse to parse the block-array form.Concurrent
complete()calls against the samebase_urlare serialised (see_get_ollama_semaphore()) because Ollama’s inference queue has effectively one slot and parallel requests interleave and degrade quality. Setmax_concurrent> 1 if your daemon is tuned for parallel inference (e.g.OLLAMA_NUM_PARALLEL=2with matching VRAM).- OLLAMA_PREFIX = 'ollama/'
- agora.fleet.llm_adapter.create_llm_adapter(model, **kwargs)[source]
Route a model string to an adapter. This is the backend SEAM: one interface (
LLMProtocol), one implementation (OllamaAdapter).Only
ollama/<model>is supported. Additional backends are re-added through the bench pipeline WITH EVIDENCE, not as kept dead code — so the factory stays a single, live branch rather than a menu of untested paths.- kwargs (all optional, forwarded to
OllamaAdapterwhen present): base_url,num_ctx,max_concurrent,keep_alive,default_max_tokens,temperature,seed,timeout_seconds.
- kwargs (all optional, forwarded to