ag2 0.8.5__py3-none-any.whl → 0.8.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ag2 might be problematic. Click here for more details.
- {ag2-0.8.5.dist-info → ag2-0.8.6.dist-info}/METADATA +175 -93
- ag2-0.8.6.dist-info/RECORD +6 -0
- ag2-0.8.5.dist-info/RECORD +0 -6
- {ag2-0.8.5.dist-info → ag2-0.8.6.dist-info}/LICENSE +0 -0
- {ag2-0.8.5.dist-info → ag2-0.8.6.dist-info}/NOTICE.md +0 -0
- {ag2-0.8.5.dist-info → ag2-0.8.6.dist-info}/WHEEL +0 -0
- {ag2-0.8.5.dist-info → ag2-0.8.6.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ag2
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.6
|
|
4
4
|
Summary: Alias package for pyautogen
|
|
5
5
|
Home-page: https://github.com/ag2ai/ag2
|
|
6
6
|
Author: Chi Wang & Qingyun Wu
|
|
@@ -14,117 +14,117 @@ Requires-Python: >=3.9,<3.14
|
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
16
|
License-File: NOTICE.md
|
|
17
|
-
Requires-Dist: pyautogen==0.8.
|
|
17
|
+
Requires-Dist: pyautogen==0.8.6
|
|
18
18
|
Provides-Extra: anthropic
|
|
19
|
-
Requires-Dist: pyautogen[anthropic]==0.8.
|
|
19
|
+
Requires-Dist: pyautogen[anthropic]==0.8.6; extra == "anthropic"
|
|
20
20
|
Provides-Extra: autobuild
|
|
21
|
-
Requires-Dist: pyautogen[autobuild]==0.8.
|
|
21
|
+
Requires-Dist: pyautogen[autobuild]==0.8.6; extra == "autobuild"
|
|
22
22
|
Provides-Extra: bedrock
|
|
23
|
-
Requires-Dist: pyautogen[bedrock]==0.8.
|
|
23
|
+
Requires-Dist: pyautogen[bedrock]==0.8.6; extra == "bedrock"
|
|
24
24
|
Provides-Extra: blendsearch
|
|
25
|
-
Requires-Dist: pyautogen[blendsearch]==0.8.
|
|
25
|
+
Requires-Dist: pyautogen[blendsearch]==0.8.6; extra == "blendsearch"
|
|
26
26
|
Provides-Extra: browser-use
|
|
27
|
-
Requires-Dist: pyautogen[browser-use]==0.8.
|
|
27
|
+
Requires-Dist: pyautogen[browser-use]==0.8.6; extra == "browser-use"
|
|
28
28
|
Provides-Extra: captainagent
|
|
29
|
-
Requires-Dist: pyautogen[captainagent]==0.8.
|
|
29
|
+
Requires-Dist: pyautogen[captainagent]==0.8.6; extra == "captainagent"
|
|
30
30
|
Provides-Extra: cerebras
|
|
31
|
-
Requires-Dist: pyautogen[cerebras]==0.8.
|
|
31
|
+
Requires-Dist: pyautogen[cerebras]==0.8.6; extra == "cerebras"
|
|
32
32
|
Provides-Extra: cohere
|
|
33
|
-
Requires-Dist: pyautogen[cohere]==0.8.
|
|
33
|
+
Requires-Dist: pyautogen[cohere]==0.8.6; extra == "cohere"
|
|
34
34
|
Provides-Extra: commsagent-discord
|
|
35
|
-
Requires-Dist: pyautogen[commsagent-discord]==0.8.
|
|
35
|
+
Requires-Dist: pyautogen[commsagent-discord]==0.8.6; extra == "commsagent-discord"
|
|
36
36
|
Provides-Extra: commsagent-slack
|
|
37
|
-
Requires-Dist: pyautogen[commsagent-slack]==0.8.
|
|
37
|
+
Requires-Dist: pyautogen[commsagent-slack]==0.8.6; extra == "commsagent-slack"
|
|
38
38
|
Provides-Extra: commsagent-telegram
|
|
39
|
-
Requires-Dist: pyautogen[commsagent-telegram]==0.8.
|
|
39
|
+
Requires-Dist: pyautogen[commsagent-telegram]==0.8.6; extra == "commsagent-telegram"
|
|
40
40
|
Provides-Extra: cosmosdb
|
|
41
|
-
Requires-Dist: pyautogen[cosmosdb]==0.8.
|
|
41
|
+
Requires-Dist: pyautogen[cosmosdb]==0.8.6; extra == "cosmosdb"
|
|
42
42
|
Provides-Extra: crawl4ai
|
|
43
|
-
Requires-Dist: pyautogen[crawl4ai]==0.8.
|
|
43
|
+
Requires-Dist: pyautogen[crawl4ai]==0.8.6; extra == "crawl4ai"
|
|
44
44
|
Provides-Extra: deepseek
|
|
45
|
-
Requires-Dist: pyautogen[deepseek]==0.8.
|
|
45
|
+
Requires-Dist: pyautogen[deepseek]==0.8.6; extra == "deepseek"
|
|
46
46
|
Provides-Extra: dev
|
|
47
|
-
Requires-Dist: pyautogen[dev]==0.8.
|
|
47
|
+
Requires-Dist: pyautogen[dev]==0.8.6; extra == "dev"
|
|
48
48
|
Provides-Extra: docs
|
|
49
|
-
Requires-Dist: pyautogen[docs]==0.8.
|
|
49
|
+
Requires-Dist: pyautogen[docs]==0.8.6; extra == "docs"
|
|
50
50
|
Provides-Extra: flaml
|
|
51
|
-
Requires-Dist: pyautogen[flaml]==0.8.
|
|
51
|
+
Requires-Dist: pyautogen[flaml]==0.8.6; extra == "flaml"
|
|
52
52
|
Provides-Extra: gemini
|
|
53
|
-
Requires-Dist: pyautogen[gemini]==0.8.
|
|
53
|
+
Requires-Dist: pyautogen[gemini]==0.8.6; extra == "gemini"
|
|
54
54
|
Provides-Extra: gemini-realtime
|
|
55
|
-
Requires-Dist: pyautogen[gemini-realtime]==0.8.
|
|
55
|
+
Requires-Dist: pyautogen[gemini-realtime]==0.8.6; extra == "gemini-realtime"
|
|
56
56
|
Provides-Extra: google-api
|
|
57
|
-
Requires-Dist: pyautogen[google-api]==0.8.
|
|
57
|
+
Requires-Dist: pyautogen[google-api]==0.8.6; extra == "google-api"
|
|
58
58
|
Provides-Extra: google-client
|
|
59
|
-
Requires-Dist: pyautogen[google-client]==0.8.
|
|
59
|
+
Requires-Dist: pyautogen[google-client]==0.8.6; extra == "google-client"
|
|
60
60
|
Provides-Extra: google-search
|
|
61
|
-
Requires-Dist: pyautogen[google-search]==0.8.
|
|
61
|
+
Requires-Dist: pyautogen[google-search]==0.8.6; extra == "google-search"
|
|
62
62
|
Provides-Extra: graph
|
|
63
|
-
Requires-Dist: pyautogen[graph]==0.8.
|
|
63
|
+
Requires-Dist: pyautogen[graph]==0.8.6; extra == "graph"
|
|
64
64
|
Provides-Extra: graph-rag-falkor-db
|
|
65
|
-
Requires-Dist: pyautogen[graph-rag-falkor-db]==0.8.
|
|
65
|
+
Requires-Dist: pyautogen[graph-rag-falkor-db]==0.8.6; extra == "graph-rag-falkor-db"
|
|
66
66
|
Provides-Extra: groq
|
|
67
|
-
Requires-Dist: pyautogen[groq]==0.8.
|
|
67
|
+
Requires-Dist: pyautogen[groq]==0.8.6; extra == "groq"
|
|
68
68
|
Provides-Extra: interop
|
|
69
|
-
Requires-Dist: pyautogen[interop]==0.8.
|
|
69
|
+
Requires-Dist: pyautogen[interop]==0.8.6; extra == "interop"
|
|
70
70
|
Provides-Extra: interop-crewai
|
|
71
|
-
Requires-Dist: pyautogen[interop-crewai]==0.8.
|
|
71
|
+
Requires-Dist: pyautogen[interop-crewai]==0.8.6; extra == "interop-crewai"
|
|
72
72
|
Provides-Extra: interop-langchain
|
|
73
|
-
Requires-Dist: pyautogen[interop-langchain]==0.8.
|
|
73
|
+
Requires-Dist: pyautogen[interop-langchain]==0.8.6; extra == "interop-langchain"
|
|
74
74
|
Provides-Extra: interop-pydantic-ai
|
|
75
|
-
Requires-Dist: pyautogen[interop-pydantic-ai]==0.8.
|
|
75
|
+
Requires-Dist: pyautogen[interop-pydantic-ai]==0.8.6; extra == "interop-pydantic-ai"
|
|
76
76
|
Provides-Extra: jupyter-executor
|
|
77
|
-
Requires-Dist: pyautogen[jupyter-executor]==0.8.
|
|
77
|
+
Requires-Dist: pyautogen[jupyter-executor]==0.8.6; extra == "jupyter-executor"
|
|
78
78
|
Provides-Extra: lint
|
|
79
|
-
Requires-Dist: pyautogen[lint]==0.8.
|
|
79
|
+
Requires-Dist: pyautogen[lint]==0.8.6; extra == "lint"
|
|
80
80
|
Provides-Extra: lmm
|
|
81
|
-
Requires-Dist: pyautogen[lmm]==0.8.
|
|
81
|
+
Requires-Dist: pyautogen[lmm]==0.8.6; extra == "lmm"
|
|
82
82
|
Provides-Extra: long-context
|
|
83
|
-
Requires-Dist: pyautogen[long-context]==0.8.
|
|
83
|
+
Requires-Dist: pyautogen[long-context]==0.8.6; extra == "long-context"
|
|
84
84
|
Provides-Extra: mathchat
|
|
85
|
-
Requires-Dist: pyautogen[mathchat]==0.8.
|
|
85
|
+
Requires-Dist: pyautogen[mathchat]==0.8.6; extra == "mathchat"
|
|
86
86
|
Provides-Extra: mcp
|
|
87
|
-
Requires-Dist: pyautogen[mcp]==0.8.
|
|
87
|
+
Requires-Dist: pyautogen[mcp]==0.8.6; extra == "mcp"
|
|
88
88
|
Provides-Extra: mistral
|
|
89
|
-
Requires-Dist: pyautogen[mistral]==0.8.
|
|
89
|
+
Requires-Dist: pyautogen[mistral]==0.8.6; extra == "mistral"
|
|
90
90
|
Provides-Extra: neo4j
|
|
91
|
-
Requires-Dist: pyautogen[neo4j]==0.8.
|
|
91
|
+
Requires-Dist: pyautogen[neo4j]==0.8.6; extra == "neo4j"
|
|
92
92
|
Provides-Extra: ollama
|
|
93
|
-
Requires-Dist: pyautogen[ollama]==0.8.
|
|
93
|
+
Requires-Dist: pyautogen[ollama]==0.8.6; extra == "ollama"
|
|
94
94
|
Provides-Extra: openai
|
|
95
|
-
Requires-Dist: pyautogen[openai]==0.8.
|
|
95
|
+
Requires-Dist: pyautogen[openai]==0.8.6; extra == "openai"
|
|
96
96
|
Provides-Extra: openai-realtime
|
|
97
|
-
Requires-Dist: pyautogen[openai-realtime]==0.8.
|
|
97
|
+
Requires-Dist: pyautogen[openai-realtime]==0.8.6; extra == "openai-realtime"
|
|
98
98
|
Provides-Extra: rag
|
|
99
|
-
Requires-Dist: pyautogen[rag]==0.8.
|
|
99
|
+
Requires-Dist: pyautogen[rag]==0.8.6; extra == "rag"
|
|
100
100
|
Provides-Extra: redis
|
|
101
|
-
Requires-Dist: pyautogen[redis]==0.8.
|
|
101
|
+
Requires-Dist: pyautogen[redis]==0.8.6; extra == "redis"
|
|
102
102
|
Provides-Extra: retrievechat
|
|
103
|
-
Requires-Dist: pyautogen[retrievechat]==0.8.
|
|
103
|
+
Requires-Dist: pyautogen[retrievechat]==0.8.6; extra == "retrievechat"
|
|
104
104
|
Provides-Extra: retrievechat-couchbase
|
|
105
|
-
Requires-Dist: pyautogen[retrievechat-couchbase]==0.8.
|
|
105
|
+
Requires-Dist: pyautogen[retrievechat-couchbase]==0.8.6; extra == "retrievechat-couchbase"
|
|
106
106
|
Provides-Extra: retrievechat-mongodb
|
|
107
|
-
Requires-Dist: pyautogen[retrievechat-mongodb]==0.8.
|
|
107
|
+
Requires-Dist: pyautogen[retrievechat-mongodb]==0.8.6; extra == "retrievechat-mongodb"
|
|
108
108
|
Provides-Extra: retrievechat-pgvector
|
|
109
|
-
Requires-Dist: pyautogen[retrievechat-pgvector]==0.8.
|
|
109
|
+
Requires-Dist: pyautogen[retrievechat-pgvector]==0.8.6; extra == "retrievechat-pgvector"
|
|
110
110
|
Provides-Extra: retrievechat-qdrant
|
|
111
|
-
Requires-Dist: pyautogen[retrievechat-qdrant]==0.8.
|
|
111
|
+
Requires-Dist: pyautogen[retrievechat-qdrant]==0.8.6; extra == "retrievechat-qdrant"
|
|
112
112
|
Provides-Extra: teachable
|
|
113
|
-
Requires-Dist: pyautogen[teachable]==0.8.
|
|
113
|
+
Requires-Dist: pyautogen[teachable]==0.8.6; extra == "teachable"
|
|
114
114
|
Provides-Extra: test
|
|
115
|
-
Requires-Dist: pyautogen[test]==0.8.
|
|
115
|
+
Requires-Dist: pyautogen[test]==0.8.6; extra == "test"
|
|
116
116
|
Provides-Extra: together
|
|
117
|
-
Requires-Dist: pyautogen[together]==0.8.
|
|
117
|
+
Requires-Dist: pyautogen[together]==0.8.6; extra == "together"
|
|
118
118
|
Provides-Extra: twilio
|
|
119
|
-
Requires-Dist: pyautogen[twilio]==0.8.
|
|
119
|
+
Requires-Dist: pyautogen[twilio]==0.8.6; extra == "twilio"
|
|
120
120
|
Provides-Extra: types
|
|
121
|
-
Requires-Dist: pyautogen[types]==0.8.
|
|
121
|
+
Requires-Dist: pyautogen[types]==0.8.6; extra == "types"
|
|
122
122
|
Provides-Extra: websockets
|
|
123
|
-
Requires-Dist: pyautogen[websockets]==0.8.
|
|
123
|
+
Requires-Dist: pyautogen[websockets]==0.8.6; extra == "websockets"
|
|
124
124
|
Provides-Extra: websurfer
|
|
125
|
-
Requires-Dist: pyautogen[websurfer]==0.8.
|
|
125
|
+
Requires-Dist: pyautogen[websurfer]==0.8.6; extra == "websurfer"
|
|
126
126
|
Provides-Extra: wikipedia
|
|
127
|
-
Requires-Dist: pyautogen[wikipedia]==0.8.
|
|
127
|
+
Requires-Dist: pyautogen[wikipedia]==0.8.6; extra == "wikipedia"
|
|
128
128
|
|
|
129
129
|
<a name="readme-top"></a>
|
|
130
130
|
|
|
@@ -189,7 +189,7 @@ The project is currently maintained by a [dynamic group of volunteers](MAINTAINE
|
|
|
189
189
|
|
|
190
190
|
## Getting started
|
|
191
191
|
|
|
192
|
-
For a step-by-step walk through of AG2 concepts and code, see [Basic Concepts](https://docs.ag2.ai/docs/user-guide/basic-concepts) in our documentation.
|
|
192
|
+
For a step-by-step walk through of AG2 concepts and code, see [Basic Concepts](https://docs.ag2.ai/latest/docs/user-guide/basic-concepts/installing-ag2/) in our documentation.
|
|
193
193
|
|
|
194
194
|
### Installation
|
|
195
195
|
|
|
@@ -252,12 +252,22 @@ We have several agent concepts in AG2 to help you build your AI agents. We intro
|
|
|
252
252
|
|
|
253
253
|
### Conversable agent
|
|
254
254
|
|
|
255
|
-
The
|
|
256
|
-
|
|
255
|
+
The [ConversableAgent](https://docs.ag2.ai/latest/docs/api-reference/autogen/ConversableAgent) is the fundamental building block of AG2, designed to enable seamless communication between AI entities. This core agent type handles message exchange and response generation, serving as the base class for all agents in the framework.
|
|
256
|
+
|
|
257
|
+
In the example below, we'll create a simple information validation workflow with two specialized agents that communicate with each other:
|
|
258
|
+
|
|
259
|
+
Note: Before running this code, make sure to set your `OPENAI_API_KEY` as an environment variable. This example uses `gpt-4o-mini`, but you can replace it with any other [model](https://docs.ag2.ai/latest/docs/user-guide/models/amazon-bedrock) supported by AG2.
|
|
257
260
|
|
|
258
261
|
```python
|
|
259
|
-
|
|
262
|
+
# 1. Import ConversableAgent class
|
|
263
|
+
from autogen import ConversableAgent, LLMConfig
|
|
264
|
+
|
|
265
|
+
# 2. Define our LLM configuration for OpenAI's GPT-4o mini
|
|
266
|
+
# uses the OPENAI_API_KEY environment variable
|
|
267
|
+
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
|
|
260
268
|
|
|
269
|
+
|
|
270
|
+
# 3. Create our LLM agent
|
|
261
271
|
with llm_config:
|
|
262
272
|
# Create an AI agent
|
|
263
273
|
assistant = ConversableAgent(
|
|
@@ -271,7 +281,7 @@ with llm_config:
|
|
|
271
281
|
system_message="You are a fact-checking assistant.",
|
|
272
282
|
)
|
|
273
283
|
|
|
274
|
-
# Start the conversation
|
|
284
|
+
# 4. Start the conversation
|
|
275
285
|
assistant.initiate_chat(
|
|
276
286
|
recipient=fact_checker,
|
|
277
287
|
message="What is AG2?",
|
|
@@ -281,25 +291,34 @@ assistant.initiate_chat(
|
|
|
281
291
|
|
|
282
292
|
### Human in the loop
|
|
283
293
|
|
|
284
|
-
|
|
294
|
+
Human oversight is crucial for many AI workflows, especially when dealing with critical decisions, creative tasks, or situations requiring expert judgment. AG2 makes integrating human feedback seamless through its human-in-the-loop functionality.
|
|
295
|
+
You can configure how and when human input is solicited using the `human_input_mode` parameter:
|
|
285
296
|
|
|
286
|
-
|
|
297
|
+
- `ALWAYS`: Requires human input for every response
|
|
298
|
+
- `NEVER`: Operates autonomously without human involvement
|
|
299
|
+
- `TERMINATE`: Only requests human input to end conversations
|
|
287
300
|
|
|
288
|
-
|
|
301
|
+
For convenience, AG2 provides the specialized `UserProxyAgent` class that automatically sets `human_input_mode` to `ALWAYS` and supports code execution:
|
|
289
302
|
|
|
290
|
-
|
|
303
|
+
Note: Before running this code, make sure to set your `OPENAI_API_KEY` as an environment variable. This example uses `gpt-4o-mini`, but you can replace it with any other [model](https://docs.ag2.ai/latest/docs/user-guide/models/amazon-bedrock) supported by AG2.
|
|
291
304
|
|
|
292
305
|
```python
|
|
293
|
-
|
|
306
|
+
# 1. Import ConversableAgent and UserProxyAgent classes
|
|
307
|
+
from autogen import ConversableAgent, UserProxyAgent, LLMConfig
|
|
308
|
+
|
|
309
|
+
# 2. Define our LLM configuration for OpenAI's GPT-4o mini
|
|
310
|
+
# uses the OPENAI_API_KEY environment variable
|
|
311
|
+
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
|
|
294
312
|
|
|
295
|
-
|
|
313
|
+
|
|
314
|
+
# 3. Create our LLM agent
|
|
296
315
|
with llm_config:
|
|
297
316
|
assistant = ConversableAgent(
|
|
298
317
|
name="assistant",
|
|
299
318
|
system_message="You are a helpful assistant.",
|
|
300
319
|
)
|
|
301
320
|
|
|
302
|
-
# Create a human agent with manual input mode
|
|
321
|
+
# 4. Create a human agent with manual input mode
|
|
303
322
|
human = ConversableAgent(
|
|
304
323
|
name="human",
|
|
305
324
|
human_input_mode="ALWAYS"
|
|
@@ -307,7 +326,7 @@ human = ConversableAgent(
|
|
|
307
326
|
# or
|
|
308
327
|
human = UserProxyAgent(name="human", code_execution_config={"work_dir": "coding", "use_docker": False})
|
|
309
328
|
|
|
310
|
-
# Start the chat
|
|
329
|
+
# 5. Start the chat
|
|
311
330
|
human.initiate_chat(
|
|
312
331
|
recipient=assistant,
|
|
313
332
|
message="Hello! What's 2 + 2?"
|
|
@@ -317,45 +336,106 @@ human.initiate_chat(
|
|
|
317
336
|
|
|
318
337
|
### Orchestrating multiple agents
|
|
319
338
|
|
|
320
|
-
|
|
339
|
+
AG2 enables sophisticated multi-agent collaboration through flexible orchestration patterns, allowing you to create dynamic systems where specialized agents work together to solve complex problems.
|
|
321
340
|
|
|
322
|
-
|
|
341
|
+
The framework offers both custom orchestration and several built-in collaboration patterns including `GroupChat` and `Swarm`.
|
|
323
342
|
|
|
324
|
-
|
|
343
|
+
Here's how to implement a collaborative team for curriculum development using GroupChat:
|
|
325
344
|
|
|
326
|
-
|
|
345
|
+
Note: Before running this code, make sure to set your `OPENAI_API_KEY` as an environment variable. This example uses `gpt-4o-mini`, but you can replace it with any other [model](https://docs.ag2.ai/latest/docs/user-guide/models/amazon-bedrock) supported by AG2.
|
|
327
346
|
|
|
328
347
|
```python
|
|
329
|
-
from autogen import ConversableAgent, GroupChat, GroupChatManager
|
|
348
|
+
from autogen import ConversableAgent, GroupChat, GroupChatManager, LLMConfig
|
|
349
|
+
|
|
350
|
+
# Put your key in the OPENAI_API_KEY environment variable
|
|
351
|
+
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
|
|
352
|
+
|
|
353
|
+
planner_message = """You are a classroom lesson agent.
|
|
354
|
+
Given a topic, write a lesson plan for a fourth grade class.
|
|
355
|
+
Use the following format:
|
|
356
|
+
<title>Lesson plan title</title>
|
|
357
|
+
<learning_objectives>Key learning objectives</learning_objectives>
|
|
358
|
+
<script>How to introduce the topic to the kids</script>
|
|
359
|
+
"""
|
|
360
|
+
|
|
361
|
+
reviewer_message = """You are a classroom lesson reviewer.
|
|
362
|
+
You compare the lesson plan to the fourth grade curriculum and provide a maximum of 3 recommended changes.
|
|
363
|
+
Provide only one round of reviews to a lesson plan.
|
|
364
|
+
"""
|
|
365
|
+
|
|
366
|
+
# 1. Add a separate 'description' for our planner and reviewer agents
|
|
367
|
+
planner_description = "Creates or revises lesson plans."
|
|
330
368
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
planner = ConversableAgent(name="planner", system_message="You create lesson plans.")
|
|
334
|
-
reviewer = ConversableAgent(name="reviewer", system_message="You review lesson plans.")
|
|
369
|
+
reviewer_description = """Provides one round of reviews to a lesson plan
|
|
370
|
+
for the lesson_planner to revise."""
|
|
335
371
|
|
|
336
|
-
|
|
337
|
-
|
|
372
|
+
with llm_config:
|
|
373
|
+
lesson_planner = ConversableAgent(
|
|
374
|
+
name="planner_agent",
|
|
375
|
+
system_message=planner_message,
|
|
376
|
+
description=planner_description,
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
lesson_reviewer = ConversableAgent(
|
|
380
|
+
name="reviewer_agent",
|
|
381
|
+
system_message=reviewer_message,
|
|
382
|
+
description=reviewer_description,
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
# 2. The teacher's system message can also be used as a description, so we don't define it
|
|
386
|
+
teacher_message = """You are a classroom teacher.
|
|
387
|
+
You decide topics for lessons and work with a lesson planner.
|
|
388
|
+
and reviewer to create and finalise lesson plans.
|
|
389
|
+
When you are happy with a lesson plan, output "DONE!".
|
|
390
|
+
"""
|
|
338
391
|
|
|
339
|
-
|
|
340
|
-
|
|
392
|
+
with llm_config:
|
|
393
|
+
teacher = ConversableAgent(
|
|
394
|
+
name="teacher_agent",
|
|
395
|
+
system_message=teacher_message,
|
|
396
|
+
# 3. Our teacher can end the conversation by saying DONE!
|
|
397
|
+
is_termination_msg=lambda x: "DONE!" in (x.get("content", "") or "").upper(),
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
# 4. Create the GroupChat with agents and selection method
|
|
401
|
+
groupchat = GroupChat(
|
|
402
|
+
agents=[teacher, lesson_planner, lesson_reviewer],
|
|
403
|
+
speaker_selection_method="auto",
|
|
404
|
+
messages=[],
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
# 5. Our GroupChatManager will manage the conversation and uses an LLM to select the next agent
|
|
408
|
+
manager = GroupChatManager(
|
|
409
|
+
name="group_manager",
|
|
410
|
+
groupchat=groupchat,
|
|
411
|
+
llm_config=llm_config,
|
|
412
|
+
)
|
|
341
413
|
|
|
342
|
-
#
|
|
343
|
-
teacher.initiate_chat(
|
|
414
|
+
# 6. Initiate the chat with the GroupChatManager as the recipient
|
|
415
|
+
teacher.initiate_chat(
|
|
416
|
+
recipient=manager,
|
|
417
|
+
message="Today, let's introduce our kids to the solar system."
|
|
418
|
+
)
|
|
344
419
|
```
|
|
345
420
|
|
|
346
|
-
|
|
421
|
+
When executed, this code creates a collaborative system where the teacher initiates the conversation, and the lesson planner and reviewer agents work together to create and refine a lesson plan. The GroupChatManager orchestrates the conversation, selecting the next agent to respond based on the context of the discussion.
|
|
347
422
|
|
|
348
|
-
|
|
423
|
+
For workflows requiring more structured processes, explore the Swarm pattern in the detailed [documentation](https://docs.ag2.ai/latest/docs/user-guide/advanced-concepts/conversation-patterns-deep-dive).
|
|
349
424
|
|
|
350
425
|
### Tools
|
|
351
426
|
|
|
352
427
|
Agents gain significant utility through tools as they provide access to external data, APIs, and functionality.
|
|
353
428
|
|
|
429
|
+
Note: Before running this code, make sure to set your `OPENAI_API_KEY` as an environment variable. This example uses `gpt-4o-mini`, but you can replace it with any other [model](https://docs.ag2.ai/latest/docs/user-guide/models/amazon-bedrock) supported by AG2.
|
|
430
|
+
|
|
354
431
|
```python
|
|
355
432
|
from datetime import datetime
|
|
356
433
|
from typing import Annotated
|
|
357
434
|
|
|
358
|
-
from autogen import ConversableAgent, register_function
|
|
435
|
+
from autogen import ConversableAgent, register_function, LLMConfig
|
|
436
|
+
|
|
437
|
+
# Put your key in the OPENAI_API_KEY environment variable
|
|
438
|
+
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
|
|
359
439
|
|
|
360
440
|
# 1. Our tool, returns the day of the week for a given date
|
|
361
441
|
def get_weekday(date_string: Annotated[str, "Format: YYYY-MM-DD"]) -> str:
|
|
@@ -364,10 +444,10 @@ def get_weekday(date_string: Annotated[str, "Format: YYYY-MM-DD"]) -> str:
|
|
|
364
444
|
|
|
365
445
|
# 2. Agent for determining whether to run the tool
|
|
366
446
|
with llm_config:
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
447
|
+
date_agent = ConversableAgent(
|
|
448
|
+
name="date_agent",
|
|
449
|
+
system_message="You get the day of the week for a given date.",
|
|
450
|
+
)
|
|
371
451
|
|
|
372
452
|
# 3. And an agent for executing the tool
|
|
373
453
|
executor_agent = ConversableAgent(
|
|
@@ -387,8 +467,10 @@ register_function(
|
|
|
387
467
|
chat_result = executor_agent.initiate_chat(
|
|
388
468
|
recipient=date_agent,
|
|
389
469
|
message="I was born on the 25th of March 1995, what day was it?",
|
|
390
|
-
max_turns=
|
|
470
|
+
max_turns=2,
|
|
391
471
|
)
|
|
472
|
+
|
|
473
|
+
print(chat_result.chat_history[-1]["content"])
|
|
392
474
|
```
|
|
393
475
|
|
|
394
476
|
### Advanced agentic design patterns
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
ag2-0.8.6.dist-info/LICENSE,sha256=GEFQVNayAR-S_rQD5l8hPdgvgyktVdy4Bx5-v90IfRI,11384
|
|
2
|
+
ag2-0.8.6.dist-info/METADATA,sha256=vWSYgbSnMORcSLias06WR_HGxhBws5-Ceulc2db2Z0w,24467
|
|
3
|
+
ag2-0.8.6.dist-info/NOTICE.md,sha256=07iCPQGbth4pQrgkSgZinJGT5nXddkZ6_MGYcBd2oiY,1134
|
|
4
|
+
ag2-0.8.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
5
|
+
ag2-0.8.6.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
6
|
+
ag2-0.8.6.dist-info/RECORD,,
|
ag2-0.8.5.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
ag2-0.8.5.dist-info/LICENSE,sha256=GEFQVNayAR-S_rQD5l8hPdgvgyktVdy4Bx5-v90IfRI,11384
|
|
2
|
-
ag2-0.8.5.dist-info/METADATA,sha256=cHuzp3Lzsw23GunfPob20So-yLiAxACsN25tHaGJTBk,20089
|
|
3
|
-
ag2-0.8.5.dist-info/NOTICE.md,sha256=07iCPQGbth4pQrgkSgZinJGT5nXddkZ6_MGYcBd2oiY,1134
|
|
4
|
-
ag2-0.8.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
5
|
-
ag2-0.8.5.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
6
|
-
ag2-0.8.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|