1
+ from typing import Annotated
1
2
import unittest
2
3
import os , logging , sys
3
4
@@ -29,7 +30,7 @@ def setUp(self):
29
30
30
31
def test_transitions (self ):
31
32
# Telling the agents to set context variables implies calling a pre-defined function call
32
- first = Agent (id = "first" , llm = self .llm , description = "Agent that sets context variables" , system_message = """You are part of an AI process
33
+ first = Agent (id = "first" , llm = self .llm , description = "Agent that sets context variables" , system_message = """You are part of an AI process
33
34
Your task is to set a context for the next agent to continue the conversation.
34
35
35
36
DO set context variable "CHANNEL" to "voice" and "LANGUAGE" to "en"
@@ -38,7 +39,7 @@ def test_transitions(self):
38
39
""" )
39
40
40
41
# Second agent might have its system message extended automatically with the context from the ongoing conversation
41
- second = Agent (id = "second" , llm = self .llm , description = "Agent that uses context variables to answer" , system_message = """You are part of an AI process
42
+ second = Agent (id = "second" , llm = self .llm , description = "Agent that uses context variables to answer" , system_message = """You are part of an AI process
42
43
Your task is to continue the conversation based on the context set by the previous agent.
43
44
When asked, you can use variable provide in CONTEXT to generate the response.
44
45
@@ -58,15 +59,15 @@ def test_transitions(self):
58
59
self .assertIn ("voice" , workflow .conversation .messages [3 ]["content" ], "Expected second agent to recognize context variable CHANNEL" )
59
60
60
61
def test_use_tools (self ):
61
- first = Agent (id = "first" , llm = self .llm , description = "Agent1" , system_message = """You are part of an AI process
62
+ first = Agent (id = "first" , llm = self .llm , description = "Agent1" , system_message = """You are part of an AI process
62
63
Your task is to support the user inquiry by providing the user profile.
63
64
""" )
64
65
65
66
@first .register_tool (name = "get_user_profile" , description = "Get the user profile" )
66
67
def get_user_profile ():
67
68
return "User profile: {\" name\" : \" John\" , \" age\" : 30}"
68
69
69
- second = Agent (id = "second" , llm = self .llm , description = "Agent2" , system_message = """You are part of an AI process
70
+ second = Agent (id = "second" , llm = self .llm , description = "Agent2" , system_message = """You are part of an AI process
70
71
Your task is to support the user inquiry by providing the user balance.
71
72
""" )
72
73
@@ -84,24 +85,24 @@ def get_user_balance():
84
85
self .assertEqual (second .id , workflow .conversation .messages [- 1 ]["name" ], "Expected user balance to be provided" )
85
86
86
87
def test_not_use_structured_output (self ):
87
- first = Agent (id = "first" , llm = self .llm , description = "Agent1" , system_message = """You are part of an AI process
88
- Your task is to support the user inquiry by providing the user profile .
88
+ first = Agent (id = "first" , llm = self .llm , description = "Agent1" , system_message = """You are part of an AI process
89
+ Your task is to support the user inquiry.
89
90
""" )
90
91
91
92
@first .register_tool (name = "get_user_profile" , description = "Get the user profile" )
92
- def get_user_profile ():
93
+ def get_user_profile () -> Annotated [ str , "The user profile, containing name and age" ] :
93
94
return "User profile: {\" name\" : \" John\" , \" age\" : 30}"
94
95
95
- second = Agent (id = "second" , llm = self .llm , description = "Agent2" , system_message = """You are part of an AI process
96
- Your task is to support the user inquiry by providing the user balance .
96
+ second = Agent (id = "second" , llm = self .llm , description = "Agent2" , system_message = """You are part of an AI process
97
+ Your task is to support the user inquiry.
97
98
""" )
98
99
99
100
@second .register_tool (name = "get_user_balance" , description = "Get the user balance" )
100
- def get_user_balance ():
101
+ def get_user_balance () -> Annotated [ str , "The user balance in USD" ] :
101
102
return "User balance: $100"
102
103
103
- flow = Team (id = "flow" , description = "" , members = [first , second ], llm = self .llm ,
104
- stop_callback = lambda x : len (x ) > 3 ,
104
+ flow = Team (id = "flow" , description = "" , members = [first , second ], llm = self .llm ,
105
+ stop_callback = lambda messages : len (messages ) == 3 ,
105
106
include_tools_descriptions = True ,
106
107
use_structured_output = False )
107
108
workflow = Workflow (askable = flow )
0 commit comments