Retries

Example demonstrating how to set up retries with an Agent.

1"""
2Retries
3=============================
4
5Example demonstrating how to set up retries with an Agent.
6"""
7
8from kern.agent import Agent
9from kern.tools.websearch import WebSearchTools
10
11# ---------------------------------------------------------------------------
12# Create Agent
13# ---------------------------------------------------------------------------
14agent = Agent(
15 name="Web Search Agent",
16 role="Search the web for information",
17 tools=[WebSearchTools()],
18 retries=3, # The Agent run will be retried 3 times in case of error.
19 delay_between_retries=1, # Delay between retries in seconds.
20 exponential_backoff=True, # If True, the delay between retries is doubled each time.
21)
22
23# ---------------------------------------------------------------------------
24# Run Agent
25# ---------------------------------------------------------------------------
26if __name__ == "__main__":
27 agent.print_response(
28 "What exactly is an AI Agent?",
29 stream=True,
30 )

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/02_agents/14_advanced
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python retries.py