The pipeline ships twoDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-ollama-crontab/llms.txt
Use this file to discover all available pages before exploring further.
agent-swarm-kit completion registrations that both target the same local Ollama model (gpt-oss:120b) but differ in how they extract structured JSON from the model’s response. OllamaOutlineToolCompletion uses Ollama’s native tool-calling API to force the model to invoke a typed provide_answer function; OllamaOutlineFormatCompletion uses Ollama’s built-in JSON format mode and parses the raw message body. Both share the same retry envelope, timeout guard, and jsonrepair-based recovery.
CompletionName Enum
Shared Constants
Both completion files define the same set of tuning constants:COMPLETION_MAX_ATTEMPTS
3 — maximum number of times the inner
while loop retries the model within a single fetchCompletion invocation before throwing "Model failed to use tool after maximum attempts".COMPLETION_MAX_RETRIES
5 — outer retry count passed to the
retry() wrapper from functools-kit. Each outer retry begins a fresh fetchCompletion execution.COMPLETION_RETRY_DELAY
5 000 ms — pause between outer retries. The
retry() wrapper waits this long before the next attempt after any thrown error.COMPLETION_TIMEOUT
300 000 ms (5 min) — per-call timeout enforced with
Promise.race. If ollama.chat() doesn’t resolve within 5 minutes, the race resolves with COMPLETION_TIMEOUT_SYMBOL and the attempt is counted as a failure.Ollama Client Configuration
Both completions obtain the Ollama client through the samegetOllama() factory from src/config/ollama.ts. It is a singleshot — the Ollama instance is created exactly once and reused for the lifetime of the process.
The default
host is https://ollama.com (the hosted Ollama cloud). For a locally-running Ollama instance, the host must be changed to http://localhost:11434 and CC_OLLAMA_TOKEN can be left empty or omitted. Adjust the params.ts environment bindings accordingly.OllamaOutlineToolCompletion (primary)
OllamaOutlineToolCompletion is the completion wired into RiskOutline. It forces the model to call a synthetic provide_answer tool, then extracts and validates the tool-call arguments as the structured response.
Registration
"ollama_outline_tool_completion" — the registry key used in addOutline({ completion: ... }).true — signals to agent-swarm-kit that this completion always returns JSON-serialisable content.["Всегда пиши ответ на русском языке", "Reasoning: high"] — metadata flags consumed by the framework for logging and prompt injection.Tool Definition
The completion dynamically constructs a tool definition from the outline’sformat parameter (the zod-derived JSON schema):
system message is prepended to every request to reinforce tool usage:
ollama.chat() Call
think: false disables chain-of-thought tokens to keep responses compact and within the timeout budget.
Inner Retry Loop
Check for tool_calls in the response
If Then
response.message.tool_calls is empty or absent, the model responded with plain text. A user message is appended (only once per outer attempt via singleshot):attempt++ and the loop continues.Parse tool_call arguments with jsonrepair
The If parsing throws, the user reminder is appended and the loop retries.
arguments field may be a raw string or already-parsed object. In either case it is stringified, repaired with jsonrepair, then parsed:Schema validation via validateToolArguments
validateToolArguments is imported from agent-swarm-kit and checks the parsed object against the JSON schema derived from the zod format.Full fetchCompletion Flow
OllamaOutlineFormatCompletion (alternative)
OllamaOutlineFormatCompletion is the simpler alternative that uses Ollama’s native format parameter to request JSON output directly, without a tool-call contract. It is useful for models that handle JSON-mode reliably but behave poorly with tool definitions.
Registration
ollama.chat() Call
tools array is passed; instead the format key activates Ollama’s constrained JSON generation. The response body (response.message.content) is then repaired and validated:
The format completion’s inner loop uses a
try/finally block that always increments attempt, meaning it does not apply the singleshot reminder-message strategy used by the tool completion. Any validation failure immediately throws and propagates to the outer retry() wrapper.Side-by-Side Comparison
- Tool Completion
- Format Completion
Method:
tools: [toolDefinition] — model must call provide_answerSchema source: Extracted from format.json_schema.schema (zod-derived OpenAI schema)Bad-response recovery: Appends user reminder, retries up to COMPLETION_MAX_ATTEMPTS times within the same outer callJSON extraction: toolCall.function.arguments → jsonrepair → JSON.parseCompletion name: "ollama_outline_tool_completion"Used by: RiskOutline (wired as completion: CompletionName.OllamaOutlineToolCompletion)