Skip to content

Commit 727006f

Browse files
committed
fix create your own agent docs
1 parent f9814bf commit 727006f

File tree

1 file changed

+3
-63
lines changed

1 file changed

+3
-63
lines changed

docs/open-source/create-your-own-agent.mdx

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ title: "Create your own AI Agent"
33
description: "How to create a custom Agent for your use case."
44
---
55

6-
# Self-hosted
7-
86
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:
97

108
Here's one that responds with the same message no matter what is said to it:
@@ -22,69 +20,11 @@ class BrokenRecordAgent(RespondAgent[BrokenRecordAgentConfig]):
2220
) -> tuple[Optional[str], bool]:
2321
return self.agent_config.message
2422

25-
def generate_response(
23+
async def generate_response(
2624
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
2826
"""Returns a generator that yields the agent's response one sentence at a time."""
29-
yield self.agent_config.message
27+
yield self.agent_config.message, False
3028
```
3129

3230
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-
class YourAgent(RESTfulAgent):
52-
53-
# input: the transcript from the Conversation that the agent must respond to
54-
async def respond(self, input: str, conversation_id: str) -> RESTfulAgentOutput:
55-
if "bye" in input:
56-
return RESTfulAgentEnd() ## ends the conversation
57-
else:
58-
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
79-
ngrok http 3000
80-
```
81-
82-
```python
83-
...
84-
agent_config=RESTfulUserImplementedAgentConfig(
85-
respond=RESTfulUserImplementedAgentConfig.EndpointConfig(
86-
url="<your ngrok url tunneling to localhost:3000>/respond",
87-
)
88-
)
89-
...
90-
```

0 commit comments

Comments
 (0)