Skip to content

How to Implement Custom Agent Providers

SPEED is provider-agnostic. You can implement a custom provider by creating a shell script that responds to five core hooks. This allows you to bridge SPEED to ANY agent CLI or local LLM server.

Implement a custom provider for a local Ollama instance.

Create lib/providers/ollama.sh. You must implement the five required functions.

#!/usr/bin/env bash
# hook 1: provider_run
# Primary entry point for executing an agent turn.
provider_run() {
local task_id="$1"
local prompt="$2"
# Call Ollama CLI or generate a request to the API
ollama run llama3 "$prompt"
}
# hook 2: provider_run_json
# Specialized entry point for agents that must return strict JSON.
provider_run_json() {
local task_id="$1"
local prompt="$2"
# Hint: Append "Reply in strict JSON" to the prompt
ollama run llama3 "$prompt. Reply only with valid JSON."
}
# hook 3: provider_spawn_bg
# Spawns a background agent process (returned as a PID).
provider_spawn_bg() {
local task_id="$1"
local prompt="$2"
ollama run llama3 "$prompt" > "logs/$task_id.log" 2>&1 &
echo $!
}
# hook 4: provider_is_running
# Checks if a background process is still active.
provider_is_running() {
local pid="$1"
kill -0 "$pid" 2>/dev/null
}
# hook 5: provider_wait
# Block until a background process completes.
provider_wait() {
local pid="$1"
wait "$pid"
}

Update speed.toml to point to your new provider:

[agent]
provider = "ollama"

Test your implementation by running a simple task:

Terminal window
speed run --max-parallel 1

SPEED expects providers to log token usage to stderr in the format Token Usage: {input}/{output}. The orchestrator uses this to update the budget analyzer.

If your provider has a rate limit, implement a “wait and retry” strategy inside provider_run. SPEED provides a log_warning helper to notify the user when the pipeline is throttled.

Always run agent commands within the git worktree provided in the agent’s environment ($AGENT_WORKTREE). This ensures that agents don’t interfere with your main repository.

SPEED passes context to agents through the provider interface. Custom providers receive these via function arguments:

Argument PositionContentExample
1stSystem prompt file pathagents/developer.md
2ndUser message (assembled context)The full Layer 3 prompt
3rdOutput file pathWhere the agent writes results
4thModel nameopus, sonnet, or haiku
5thAllowed tools"Bash Edit Read Write Glob Grep"
6thWorking directory (worktree path).speed/worktrees/task-3

The working directory (6th argument) is the isolated git worktree for the task. Agents should execute all commands within this directory. SPEED manages three tool permission levels:

VariableToolsUsed by
AGENT_TOOLS_FULLBash Edit Read Write Glob GrepDeveloper agents (full read/write + shell)
AGENT_TOOLS_WRITERead Write GlobFile manipulation only (no shell)
AGENT_TOOLS_READONLYRead Glob GrepRead-only agents (Reviewer, Auditor, Guardian)
  • All five shell hooks (run, run_json, spawn, is_running, wait) are implemented.
  • The script is executable (chmod +x).
  • speed.toml uses the provider name matching your filename.
  • Tokens are logged to stderr for budget tracking.