MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / main

Function main

examples/ag2/ag2_async_agent.py:101–153  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99
100
101async def main():
102 print("🚀 Starting AG2 Async Demo")
103
104 # Create agents with automated behavior
105 user_proxy = AutomatedUserProxyAgent(
106 name="hiring_manager",
107 human_input_mode="NEVER", # No human input required
108 max_consecutive_auto_reply=3,
109 code_execution_config=False,
110 is_termination_msg=lambda msg: "TERMINATE" in str(msg.get("content", "")),
111 )
112
113 assistant = AsyncAssistantAgent(
114 name="interview_consultant",
115 system_message="""You are an expert interview consultant. When given interview topics,
116 you create thoughtful, relevant questions. You ask for feedback and incorporate it.
117 When the user is satisfied with the questions, end with 'TERMINATE'.""",
118 llm_config={"config_list": [{"model": "gpt-4o-mini", "api_key": os.environ.get("OPENAI_API_KEY")}]},
119 is_termination_msg=lambda msg: "TERMINATE" in str(msg.get("content", "")),
120 )
121
122 try:
123 print("🤖 Initiating automated conversation...")
124 # Start the automated chat between the user and assistant
125 await user_proxy.a_initiate_chat(
126 assistant,
127 message="""I need help creating interview questions for these topics:
128 - Resume Review
129 - Technical Skills Assessment
130 - Project Discussion
131 - Job Role Expectations
132 - Closing Remarks
133
134 Please create 2-3 questions for each topic.""",
135 max_turns=6,
136 )
137
138 # Let's check programmatically that spans were recorded in AgentOps
139 print("\n" + "=" * 50)
140 print("Now let's verify that our LLM calls were tracked properly...")
141 try:
142 agentops.validate_trace_spans(trace_context=tracer)
143 print("\n✅ Success! All LLM spans were properly recorded in AgentOps.")
144 except agentops.ValidationError as e:
145 print(f"\n❌ Error validating spans: {e}")
146 raise
147
148 except Exception as e:
149 print(f"\n❌ Error occurred: {e}")
150 finally:
151 agentops.end_trace(tracer, end_state="Success")
152
153 print("\n🎉 Demo completed successfully!")
154
155
156# Run the main async demo

Callers 1

ag2_async_agent.pyFile · 0.70

Calls 4

AsyncAssistantAgentClass · 0.85
end_traceMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…