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
Copy file name to clipboardExpand all lines: docs/open-source/create-your-own-agent.mdx
+3-63Lines changed: 3 additions & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,6 @@ title: "Create your own AI Agent"
3
3
description: "How to create a custom Agent for your use case."
4
4
---
5
5
6
-
# Self-hosted
7
-
8
6
You can subclass a [`RespondAgent`](https://github.com/vocodedev/vocode-python/blob/main/vocode/streaming/agent/base_agent.py#L140) to create a simple agent that can be passed into [`StreamingConversation`](https://github.com/vocodedev/vocode-python/blob/main/vocode/streaming/streaming_conversation.py) has the following interface:
9
7
10
8
Here's one that responds with the same message no matter what is said to it:
@@ -22,69 +20,11 @@ class BrokenRecordAgent(RespondAgent[BrokenRecordAgentConfig]):
22
20
) -> tuple[Optional[str], bool]:
23
21
returnself.agent_config.message
24
22
25
-
defgenerate_response(
23
+
asyncdefgenerate_response(
26
24
self, human_input, is_interrupt: bool=False
27
-
) -> Generator[str, None, None]:
25
+
) -> AsyncGenerator[Tuple[str, bool], None]:# message and whether or not the message is interruptible
28
26
"""Returns a generator that yields the agent's response one sentence at a time."""
29
-
yieldself.agent_config.message
27
+
yieldself.agent_config.message, False
30
28
```
31
29
32
30
See [our other agent implementations](https://github.com/vocodedev/vocode-python/tree/main/vocode/streaming/agent) for more guidance!
33
-
34
-
# Hosted (deprecated)
35
-
36
-
NOTE: The hosted `RESTfulAgent` is being deprecated.
37
-
38
-
Our library lets you easily host your agent so that the Vocode backend can use it to generate responses.
39
-
Users will be responsible for implementing a `RESTfulAgent`.
40
-
41
-
## RESTful Implementation (deprecated)
42
-
43
-
Here is an example implementation of a `RESTfulAgent` that just echoes back whatever
44
-
input it receives. Note that the `respond` method is expecting a `RESTfulAgentOutput` return value.
45
-
The `conversation_id` parameter lets you store state about a single conversation across multiple calls.
46
-
47
-
```python
48
-
from vocode.streaming.user_implemented_agent.restful_agent import RESTfulAgent
49
-
from vocode.streaming.models.agent import RESTfulAgentOutput, RESTfulAgentText, RESTfulAgentEnd
50
-
51
-
classYourAgent(RESTfulAgent):
52
-
53
-
# input: the transcript from the Conversation that the agent must respond to
return RESTfulAgentText(response=input) ## responds with the input received
59
-
```
60
-
61
-
## Run your agent
62
-
63
-
```
64
-
if __name__ == "__main__":
65
-
agent = YourAgent()
66
-
agent.run(port=3000)
67
-
```
68
-
69
-
This sets up a [FastAPI](https://fastapi.tiangolo.com/) with either a POST endpoint or a websocket route at `/respond`.
70
-
We'll use this in the next step.
71
-
72
-
## Setting up your `AgentConfig`
73
-
74
-
Now that your agent is running, you'll need to host it somewhere so that the Vocode backend can hit it.
75
-
There are a variety of options to do this, here we'll describe using [ngrok](https://ngrok.com/) since it's the quickest. [Replit](https://replit.com/) is also a great option for this.
76
-
77
-
```bash
78
-
# make sure the agent from the last step is running
0 commit comments