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

create_llm_adapter(model, **kwargs)

Route a model string to an adapter.

Classes

LLMProtocol

Minimal async interface every backend must satisfy.

LLMResponse

One assistant turn from the underlying model.

OllamaAdapter

Ollama HTTP adapter.

ToolCall

One tool invocation in an assistant turn.

class agora.fleet.llm_adapter.ToolCall[source]

Bases: object

One tool invocation in an assistant turn.

id is the provider-assigned identifier the runtime echoes back in the tool-result message. name matches a registered inner tool; arguments is the parsed JSON object the model emitted.

id: str
name: str
arguments: dict[str, Any]
__init__(id, name, arguments)
class agora.fleet.llm_adapter.LLMResponse[source]

Bases: object

One assistant turn from the underlying model.

content is the plaintext component (often empty when the turn is pure tool-use). tool_calls are the tool invocations the runtime will execute and feed results back for. usage carries provider token counters (input/output). stop_reason is the termination signal, propagated so callers can distinguish budget exhaustion from natural completion.

content: str
tool_calls: tuple[ToolCall, ...] = ()
usage: dict[str, int]
stop_reason: str = ''
thinking: str = ''
__init__(content, tool_calls=(), usage=<factory>, stop_reason='', thinking='')
class agora.fleet.llm_adapter.LLMProtocol[source]

Bases: Protocol

Minimal 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 is OllamaAdapter; tests inject a fake.

async complete(messages, system='', tools=None, model='', max_tokens=4096)[source]
format_assistant_turn(response)[source]
format_tool_results(calls, results)[source]
__init__(*args, **kwargs)
class agora.fleet.llm_adapter.OllamaAdapter[source]

Bases: object

Ollama HTTP adapter. Talks to a local or remote Ollama daemon.

Uses Ollama’s OpenAI-style role: tool messages for tool results instead of a tool_result block-array shape — many local models refuse to parse the block-array form.

Concurrent complete() calls against the same base_url are serialised (see _get_ollama_semaphore()) because Ollama’s inference queue has effectively one slot and parallel requests interleave and degrade quality. Set max_concurrent > 1 if your daemon is tuned for parallel inference (e.g. OLLAMA_NUM_PARALLEL=2 with matching VRAM).

OLLAMA_PREFIX = 'ollama/'
__init__(base_url, timeout_seconds=600.0, num_ctx=16384, max_concurrent=1, default_model='', keep_alive='30m', default_max_tokens=4096, temperature=None, seed=None, on_text_fallback=None)[source]
format_assistant_turn(response)[source]
format_tool_results(calls, results)[source]
async complete(messages, system='', tools=None, model='qwen2.5-coder:7b-instruct', max_tokens=None)[source]
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 OllamaAdapter when present):

base_url, num_ctx, max_concurrent, keep_alive, default_max_tokens, temperature, seed, timeout_seconds.