Skip to content

feat: Configurable max tool calls per agent (guardrails) #379

Open

Description

@vybe

Summary

Allow per-agent configuration of the maximum tool calls limit in guardrails. Currently hardcoded at 50 (recently increased from 20), but different agents have different needs.

Context

From weekly meeting (2026-04-17): Eugene's agent system was failing because agents were making many tool calls and hitting the 20-call limit. Increased to 50 as a workaround, but this should be configurable per-agent.

Some agents (research, code generation) legitimately need 50+ tool calls. Others should stay constrained for cost/safety.

Acceptance Criteria

  • Add max_tool_calls field to agent settings (default: 50)
  • Expose in Agent Detail UI → Settings tab
  • Guardrail system reads per-agent limit instead of global constant
  • MCP tool to get/set this setting
  • Document in agent configuration reference

Technical Notes

Related to GUARD-001 (Lesha's guardrails work).

Files:

  • src/backend/db/agent_settings/ - Add new mixin
  • src/backend/routers/agent_config.py - Add endpoint
  • Agent server guardrail enforcement code

Activity

  1. added
    priority-p2
    type-feature
    on Apr 17, 2026
  2. kinthaiofficial commented on Apr 28, 2026

    @kinthaiofficial

    Per-agent tool call limits is the right granularity. We run 221 agents at KinthAI and different agent types have wildly different tool call needs — our research agents routinely hit 80+ tool calls while our simple Q&A agents rarely exceed 5.

    Design recommendations beyond max_tool_calls:

    1. Budget by cost, not by count:

    A max of 50 tool calls treats a cheap embedding lookup the same as an expensive API call. We use a two-dimensional budget: max_tool_calls (hard count limit) AND max_tool_cost (total estimated cost of tool calls). The cost-based limit catches scenarios where an agent makes 10 tool calls but each one is expensive.

    2. Per-tool-type limits:

    Some agents should be allowed unlimited read operations but limited write operations. We support per-tool limits: {"search": unlimited, "file_write": 5, "api_call": 20}. This is more nuanced than a global count and prevents agents from exhausting their budget on low-value operations.

    3. Circuit breaker integration:

    When an agent hits its tool call limit, the current behavior is usually a hard stop. Better: give the agent one final turn to produce best-effort output from what it has so far. A research agent with 50 results is better than a crashed agent with 0 results.

    4. Dynamic limit adjustment:

    For agents that consistently hit the limit, we auto-suggest a higher limit (with human approval). For agents that consistently use <10% of their limit, we suggest lowering it. This keeps the configuration aligned with actual usage patterns.

    Multi-agent coordination patterns: 221 Agents: Multi-Agent Coordination Lessons

  3. added
    complexity-low
    theme-security
    on Jun 3, 2026
  4. Keesan12 commented on Jun 3, 2026

    @Keesan12

    One implementation detail I would strongly recommend: make the limit policy describe what happens when the limit is reached, not only the number.

    For example:

    type ToolCallLimitPolicy = {
      maxToolCalls: number
      mode: "hard_stop" | "finalize_from_context" | "request_approval"
      perToolOverrides?: Record<string, number>
      resetScope: "run" | "conversation" | "day"
    }

    Different agent classes need different failure behavior. A support/Q&A agent can hard-stop. A research or coding agent usually needs one tool-free final turn to explain partial progress, blockers, and the exact next action. A write-capable agent may need approval rather than a bigger budget.

    The UI would be more useful if it showed both:

    • configured limit: 50 tool calls/run
    • last-run receipt: 43 used, 0 blocked, stopped_reason=completed

    That turns this from a static setting into an operator feedback loop. If you later add auto-suggestions, you can base them on receipts rather than guessing from failures.

    This is also the kind of control surface MartinLoop is focused on: budget cap, verifier gate, run receipt. We launched on Product Hunt yesterday if a concrete UX comparison helps: https://www.producthunt.com/products/martinloop

  5. added
    status-incubating
    on Jun 14, 2026
  6. added
    complexity-medium
    and removed
    complexity-low
    on Sep 2, 2026
  7. added
    status-ready
    and removed
    status-incubating
    on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p2status-readytheme-securitytype-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions