Skip to content

[NEW CONTENT] Limit agent execution in productoin #567

@Unshure

Description

@Unshure

Proposed Content

We should include information that some kind of limit should be applied to agents when deployed in production. This could be a timeout, token, or agent loop limit for agents.

Location

https://strandsagents.com/latest/documentation/docs/user-guide/deploy/operating-agents-in-production/

Rationale

Give instruction that agents should have clear execution boundaries, and should not be able to run forever.

Content Outline (Optional)

No response

References

related: #189


Implementation Requirements

Based on repository analysis and clarification discussion, this task involves adding documentation about execution limits to the production guide.

Target File

docs/user-guide/deploy/operating-agents-in-production.md

Placement

Integrate into the existing "Performance Optimization" section as a new subsection covering execution limits and safety boundaries.

Content to Add

Execution Limits Subsection

Add conceptual guidance covering the following limit types:

  1. Agent Loop Iteration Limits

    • Limiting the maximum number of LLM calls per agent invocation
    • Reference: Hook-based approach using BeforeModelCallEvent / AfterModelCallEvent
  2. Tool Invocation Limits

    • Limiting how many times tools can be called
    • Reference: Existing LimitToolCounts hook example in Hooks - Cookbook
  3. Token Consumption Budgets

  4. Execution Timeouts

    • Wall-clock time limits for agent invocations
    • Hook-based or external wrapper approaches

Multi-Agent Safety Mechanisms Reference

Include a subsection referencing built-in safety mechanisms for multi-agent patterns:

Code Examples

  • Conceptual guidance only - point to existing hook examples rather than creating new code
  • Include Python examples with TypeScript equivalents where the feature is available
  • Use {{ ts_not_supported_code() }} macro for features not yet available in TypeScript

Documentation Style

  • Follow existing documentation patterns in operating-agents-in-production.md
  • Use cross-references to existing documentation sections
  • Include rationale for why execution limits are important (cost control, preventing infinite loops, resource management)

Files to Modify

  • docs/user-guide/deploy/operating-agents-in-production.md - Add execution limits subsection

Acceptance Criteria

  • New "Execution Limits" subsection added under "Performance Optimization"
  • All four limit types covered with conceptual guidance
  • Cross-references to existing hook documentation (hooks.md)
  • Cross-references to multi-agent safety mechanisms (swarm.md, graph.md)
  • Python examples included
  • TypeScript equivalents included where available (or macro used for unavailable features)
  • Documentation builds successfully (mkdocs build)
  • TypeScript validation passes (npm run test)

Related Issues

Notes for Implementation

  • The existing LimitToolCounts hook in hooks.md provides a good pattern to reference
  • Multi-agent patterns (Swarm/Graph) have built-in limits that should be highlighted as best practices
  • Consider adding a brief note about monitoring token usage (ties into existing "Monitoring and Observability" section)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions