Agents
Connecting Your Agent
How to link a custom agent to your app
Agent Factories
Agent factories specify which agents are available to your app. In order to connect an agent to your app, you must first define an agent factory. To do so, subclass the AbstractAgentFactory
class to specify how agents are created. Here you can import and use your own custom agents.
Example
First define your AgentFactory
. In this example, we are creating a factory for a new type of agent called MyActionAgent:
from vocode.streaming.agent.abstract_factory import AbstractAgentFactory
from vocode.streaming.action.my_action_factory import MyActionFactory
class MyAgentFactory(AbstractAgentFactory):
def __init__(self, action_factory: MyActionFactory):
self.action_factory = action_factory
def create_agent(
self, agent_config: AgentConfig, logger: Optional[logging.Logger] = None
) -> BaseAgent:
if agent_config.type == "MY_ACTION":
return MyActionAgent(
agent_config=agent_config,
action_factory=self.action_factory
)
elif agent_config.type == "other_agent_type":
...
else:
raise Exception("Invalid agent config")
Then, in your app, you can connect the agent to the app:
from vocode.streaming.telephony.server.base import TelephonyServer
from vocode.streaming.agent.my_agent_factory import MyAgentFactory
from vocode.streaming.action.my_action_factory import MyActionFactory
telephony_server = TelephonyServer(
agent_factory=MyAgentFactory(action_factory=MyActionFactory())
...
)