Demonstrate basic agent creation and team coordination. This function shows how to: 1. Create specialized agents with specific roles 2. Organize agents into a team 3. Use the team to solve tasks that require multiple perspectives
()
| 41 | |
| 42 | |
| 43 | def demonstrate_basic_agents(): |
| 44 | """ |
| 45 | Demonstrate basic agent creation and team coordination. |
| 46 | |
| 47 | This function shows how to: |
| 48 | 1. Create specialized agents with specific roles |
| 49 | 2. Organize agents into a team |
| 50 | 3. Use the team to solve tasks that require multiple perspectives |
| 51 | """ |
| 52 | tracer = agentops.start_trace(trace_name="Agno Basic Agents and Teams Demonstration") |
| 53 | |
| 54 | try: |
| 55 | # Create individual agents with specific roles |
| 56 | # Each agent has a name and a role that defines its expertise |
| 57 | |
| 58 | # News Agent: Specializes in gathering and analyzing news information |
| 59 | news_agent = Agent( |
| 60 | name="News Agent", role="Get the latest news and provide news analysis", model=OpenAIChat(id="gpt-4o-mini") |
| 61 | ) |
| 62 | |
| 63 | # Weather Agent: Specializes in weather forecasting and analysis |
| 64 | weather_agent = Agent( |
| 65 | name="Weather Agent", |
| 66 | role="Get weather forecasts and provide weather analysis", |
| 67 | model=OpenAIChat(id="gpt-4o-mini"), |
| 68 | ) |
| 69 | |
| 70 | # Create a team with coordination mode |
| 71 | # The "coordinate" mode allows agents to work together and share information |
| 72 | team = Team( |
| 73 | name="News and Weather Team", |
| 74 | mode="coordinate", # Agents will coordinate their responses |
| 75 | members=[news_agent, weather_agent], |
| 76 | ) |
| 77 | |
| 78 | # Run a task that requires team coordination |
| 79 | # The team will automatically determine which agent(s) should respond |
| 80 | response = team.run("What is the weather in Tokyo?") |
| 81 | |
| 82 | print("\nTeam Response:") |
| 83 | print("-" * 60) |
| 84 | print(f"{response.content}") |
| 85 | print("-" * 60) |
| 86 | |
| 87 | agentops.end_trace(tracer, end_state="Success") |
| 88 | |
| 89 | except Exception as e: |
| 90 | print(f"An error occurred: {e}") |
| 91 | agentops.end_trace(tracer, end_state="Error") |
| 92 | |
| 93 | # Let's check programmatically that spans were recorded in AgentOps |
| 94 | print("\n" + "=" * 50) |
| 95 | print("Now let's verify that our LLM calls were tracked properly...") |
| 96 | try: |
| 97 | agentops.validate_trace_spans(trace_context=tracer) |
| 98 | print("\n✅ Success! All LLM spans were properly recorded in AgentOps.") |
| 99 | except agentops.ValidationError as e: |
| 100 | print(f"\n❌ Error validating spans: {e}") |
no test coverage detected
searching dependent graphs…