📧 chinmayeepavi@gmail.com Support

Best Practices

Safety & Guardrails

# Always implement safety checks
class SafeAgent:
    def __init__(self, agent, max_iterations=10, max_cost=1.0):
        self.agent = agent
        self.max_iterations = max_iterations
        self.max_cost = max_cost
        self.iteration_count = 0
        self.total_cost = 0

    def invoke(self, input):
        self.iteration_count += 1
        if self.iteration_count > self.max_iterations:
            raise Exception("Max iterations reached - possible infinite loop")
        if self.total_cost > self.max_cost:
            raise Exception("Cost limit exceeded")
        return self.agent.invoke(input)

Key Principles

  1. Start simple — Begin with a single agent and few tools; add complexity gradually
  2. Limit scope — Define clear boundaries for what the agent can and cannot do
  3. Implement guardrails — Set max iterations, cost limits, and action restrictions
  4. Log everything — Record all agent decisions, tool calls, and outputs for debugging
  5. Human oversight — Keep humans in the loop for critical actions (payments, deletions, external communications)
  6. Test adversarially — Try to break your agent with edge cases and malicious inputs
  7. Use structured outputs — Force agents to respond in predictable formats (JSON, function calls)
  8. Handle failures gracefully — Agents will make mistakes; design for recovery