AgentTool logo

Most coding assistants phone home to the cloud. AgentTool does the opposite — it runs an agentic coding loop entirely on models served from your own machine, keeping your code local and your context private.

Problem

Developers who want AI-assisted coding face a false choice: send proprietary code to cloud APIs, or accept limited local models with poor tool-calling reliability. Existing local-first tools either lack a robust tool-calling loop, fail on non-conformant model outputs, or require complex setup. AgentTool targets developers who need a local-first, reliable, hackable agentic assistant that works with any OpenAI-compatible server (Ollama, LM Studio, vLLM).

Constraints

  • Local-first: No outbound network calls except to the user’s chosen model server
  • Model-agnostic: Must work with any OpenAI-compatible /chat/completions endpoint
  • Robust to malformed output: Local models frequently emit invalid JSON; the tool loop must recover
  • Interrupt-safe: Ctrl-C must unwind cleanly without corrupting state
  • Test-backed: Behavior must be verified by CI, not vibes
  • Zero-config startup: Auto-detect Ollama/LM Studio; sensible defaults

Architecture & Design Decisions

The assistant is a loop: observe state → model chooses tool → execute → feed result back → repeat. The tool-calling protocol follows the OpenAI-compatible schema, so any server exposing that interface works without code changes.

Tool-Calling Loop & Fallback Parsing

Decision: Implement a primary JSON parser with a permissive fallback parser that extracts tool calls from malformed model output.

Why: Local models (especially smaller ones) often emit JSON with trailing commas, missing quotes, or explanatory text. The fallback parser uses regex + heuristic recovery to salvage usable calls, dramatically improving success rates on 7B–14B models.

Tradeoff: Fallback parsing adds complexity and can occasionally misfire. Alternative: require structured output / constrained decoding (not universally supported across local servers).

Tool Set

Bundled tools cover the core coding workflow. The repo exposes 8 tools, each with a dispatch unit test:

  • web_search — DuckDuckGo search via ddgs
  • read_file / write_file — file I/O (write creates parent directories)
  • list_directory — directory listing
  • grep_search — regex search across a file or directory
  • diff — unified diff between two files
  • edit_file — substring replacement with ambiguity guard and replace_all
  • run_command — shell command with a 30-second timeout

Decision: Keep tools minimal and composable. Each tool is a pure function with explicit input/output schemas.

Configuration & Auto-Discovery

Decision: Zero-config by default. On startup, probe http://localhost:11434 (Ollama) and http://localhost:1234 (LM Studio); use first responding. Allow override via --model-url and --model-name.

Tradeoff: Simplicity vs. explicit config. Advanced users can still use config file or env vars.

Testing Strategy

Decision: A pytest suite of 55 tests, split between tests/test_agent.py (22) and tests/test_tools.py (33), covering:

  • Unit tests for each of the 8 tools and their dispatch
  • Model discovery with mocked HTTP responses
  • Streaming-chunk reassembly and tool-call parsing, using mocked model responses
  • CI on push/PR to main, linted with ruff, type-checked with mypy, and tested on Python 3.10–3.13

Why: Local-first tools are hard to debug in production; tests are the primary safety net. The full agent loop is not covered by an end-to-end test — only its model-response path is unit-tested.

Evaluation

Performance figures such as fallback-parser recovery rate and cold-start latency are not published here: measuring them requires a controlled local-model benchmark, and no such results exist in the repo. The values below are verifiable directly from the source and test suite at commit d76f51f.

MetricVerified valueSource
Fallback output formats handled6TestRobustToolParse: JSON in prose, name(...), toolInvocation, list-wrapped toolInvocation, name:, name=
Tools exposed and dispatch-tested8tools.py::TOOL_DEFINITIONS and TestExecuteTool
Model servers discovered2 (Ollama, LM Studio), 2 s probe timeout eachagent.py::_fetch_ollama_models / _fetch_lmstudio_models
Maximum agent-loop iterations10agent.py::run_agent_loop(max_iters=10)
Test suite55 collected; 54 passed, 1 timeout test deselectedpytest tests/ locally; .github/workflows/ci.yml on Python 3.10–3.13
Shell command timeout30 stools.py::run_command

Limitations

  • No sandboxing: Shell tool runs with user’s full permissions. Not safe for untrusted model output in multi-user contexts.
  • Single-threaded loop: No parallel tool execution; complex tasks take linear time.
  • Context window management: Naïve truncation; no summarization or RAG over conversation history.
  • Model support: Only OpenAI-compatible tool calling; no native support for Anthropic, Google, or custom schemas.
  • No GUI/TUI: Pure CLI; output can be verbose for long sessions.

What’s Next

  1. Add a benchmark harness — publish measured fallback-recovery and cold-start figures instead of the unverified ones removed above
  2. Implement context summarization — auto-summarize older turns when approaching context limit
  3. Add structured-output enforcement — use json_schema / grammar params where server supports it
  4. Add tool confirmation and namespace-aware TUI controls — richer terminal UI on top of the existing Rich/prompt-toolkit interface
  5. Publish to PyPI — pyproject.toml and packaging/ already define the agenttool entry point

Already shipped: session persistence with resume (SESSION_DIR, _save_message, _load_messages, resume_session).

Repository

★ AgentTool
A local-first, agentic coding assistant with a tested tool-calling loop. Runs entirely on your own hardware.
1 star Python Apache-2.0
View on GitHub →

Further Reading