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
@@ -51,24 +51,76 @@ The flow of actions is as follows:
51
51
5. The agent then consumes the `ActionResultAgentInput` from the queue in its process method. This
52
52
result is added to the transcript of the conversation, and can influence the behavior of the agent in subsequent interactions.
53
53
54
-
###Implementing your own action: Nylas email example
54
+
## Implementing your own action: Nylas email example
55
55
56
56
In this section, we provide an example of an action, `NylasSendEmail`, which extends the `BaseAction` class. It implements the run method to send an email using the Nylas API.
57
+
We will also show how to add this action to an agent and use it in a conversation.
The input to this action is a pipe separated list of the recipient email, email body, optional subject. But always include
63
-
the pipe character even if the subject or message IDs are not included and just leave it blank.
64
-
The subject should only be included if it is a new email thread.
65
-
If there is no message id, the email will be sent as a new email. Otherwise, it will be sent as a reply to the given message. Make sure to include the previous message_id
66
-
if you are replying to an email.
67
-
68
-
For example, `[email protected]|Hello, this is the email body.|this is the subject` would send an email to [email protected] with the provided body and subject.
from vocode.streaming.action.base_action import BaseAction
68
+
from vocode.streaming.models.actions import ActionConfig as VocodeActionConfig
69
+
from vocode.streaming.models.actions import ActionInput, ActionOutput
70
+
71
+
72
+
_NYLAS_ACTION_DESCRIPTION="""Sends an email using Nylas API.
73
+
The input to this action is the recipient emails, email body, optional subject.
74
+
The subject should only be included if it is a new email thread.
75
+
If there is no message id, the email will be sent as a new email. Otherwise, it will be sent as a reply to the given message. Make sure to include the previous message_id
76
+
if you are replying to an email.
77
+
"""
78
+
79
+
80
+
classNylasSendEmailParameters(BaseModel):
81
+
email: str= Field(..., description="The email address to send the email to.")
82
+
subject: Optional[str] = Field(None, description="The subject of the email.")
83
+
body: str= Field(..., description="The body of the email.")
We define a structured set of parameters that the LLM will fill, a response structure that the agent can ingest and use as context for the rest of the conversation, and an action
153
+
config that crucially contains the `action_type` (but doesn't have any other specific parameters). We also add an `_end_of_run_hook()` that we customized to log that the action successfully completed.
154
+
155
+
156
+
### Making a custom `ActionFactory`
157
+
To use our new action with an agent in a conversation, we will need to create an `ActionFactory` that can produce instances your custom action.
158
+
159
+
160
+
We will store the code above in `nylas_send_email.py` and create a factory that can create this action for an agent:
161
+
162
+
```python
163
+
from typing import Dict, Sequence, Type
164
+
165
+
from vocode.streaming.action.abstract_factory import AbstractActionFactory
166
+
from vocode.streaming.action.base_action import BaseAction
167
+
from vocode.streaming.action.nylas_send_email import NylasSendEmail
168
+
from vocode.streaming.models.actions import ActionConfig
if action_config.type =="action_nylas_send_email":
173
+
return NylasSendEmail(action_config)
174
+
else:
175
+
raiseException("Action type not supported by Agent config.")
176
+
```
177
+
178
+
### Using your action and action factory in an agent
179
+
180
+
Now you can use your action in any conversation by adding the action config to any agent config and passing in your action factory. For example, you can create a ChatGPT agent config:
181
+
182
+
```python
183
+
action_config = ChatGPTAgentConfig(
184
+
...
185
+
actions= [
186
+
NylasSendEmailVocodeActionConfig(
187
+
type="action_nylas_send_email"
188
+
)
189
+
]
190
+
)
94
191
```
95
192
96
-
See [Agent Factory](/open-source/agent-factory) for more information on how to register your action with the agent factory.
193
+
Now, you have a config for an agent that uses your new action! When you pass in your new action factory [created above](#making-a-custom-actionfactory), any agent factory can generate this agent for conversations.
194
+
See [Agent Factory](/open-source/agent-factory) for more information on how to use your action factory in an agent factory, as well as how to plug it into a telephony server.
Copy file name to clipboardexpand all lines: docs/open-source/external-action.mdx
+12-14
Original file line number
Diff line number
Diff line change
@@ -221,9 +221,9 @@ fastapi==0.111.*
221
221
222
222
</CodeGroup>
223
223
224
-
## Meeting Assistant Example:
224
+
## Meeting Assistant Example
225
225
226
-
This is an example of how to configure a Meeting Assistant Action which will attempt to book a meeting for30 minutes or an hour at any time ending in a zero (ie 10:30amis okay but 10:35amisnot)
226
+
This is an example of how to create an action config which will attempt to book a meeting for30 minutes or an hour at any time ending in a zero (ie 10:30amis okay but 10:35amisnot)
227
227
228
228
```python Python
229
229
import json
@@ -249,17 +249,15 @@ ACTION_INPUT_SCHEMA = {
249
249
},
250
250
}
251
251
252
-
action_config = {
253
-
"name": "Meeting_Booking_Assistant",
254
-
"description": "Book a meeting for a 30 minute or 1 hour call.",
See [Action Agents](/open-source/action-agents#using-your-action-and-action-factory-in-an-agent) for an example of how to use this action config with an agent in a conversation.
263
+
Note that you do not need to create a custom action factory, since `DefaultActionFactory` already supports external actions.
0 commit comments