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()`, which 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 of the action.
158
+
159
+
160
+
We will store the code above in `nylas_send_email.py` and make 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 an agent config. For example in a ChatGPTAgentConfig,
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
+
When you pass in your new action factory [created above](#making-a-custom-actionfactory), any agent factory can use this config to generate an 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.
0 commit comments