You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Chat Agents enable interactive conversations with AI agents that can execute functions. They are simpler to use than full Agents and are ideal for chatbot-like interactions where the agent can perform actions.
args=[Argument(name="prompt", description="The prompt for the picture")],
135
+
executable=generate_picture
136
+
)
137
+
]
138
+
139
+
# Create a chat session
140
+
chat = chat_agent.create_chat(
141
+
partner_id="user123",
142
+
partner_name="User Name",
143
+
action_space=[list_of_functions], # Optional
144
+
get_state_fn=lambda: {...} # Optional, allows to push state of the environment to the agent
145
+
)
146
+
147
+
# Run conversation
148
+
chat_continue =True
149
+
while chat_continue:
150
+
user_message =input("Enter a message: ")
151
+
response = chat.next(user_message)
152
+
...
153
+
if response.is_finished:
154
+
chat_continue =False
155
+
156
+
# End chat
157
+
chat.end("Optional ending message")
158
+
```
159
+
160
+
### Chat Termination
161
+
162
+
The chat can be terminated in two ways:
163
+
164
+
1.**Agent-initiated**: The agent may decide to end the chat on its own when it determines the conversation is complete. In this case, `chat.next()` will return `False`.
165
+
166
+
2.**Client-initiated**: The client can manually end the chat at any time by calling:
167
+
```python
168
+
chat.end("Optional farewell message")
169
+
```
170
+
171
+
### Chat Memory
172
+
173
+
ChatAgent maintains a simple short-term memory by keeping track of recent messages in the conversation. This allows the agent to maintain context and provide coherent responses based on the conversation history. The memory is temporary and limited to the current chat session.
0 commit comments