- Configure sessions, which involves setting fields such as your speech-to-text provider, initial messages, etc.
- Define how your LLM responds to users during sessions.
- Define your agent.
Configuring sessions
Sessions are configured in theconfigure_session function, which is called at the beginning of
every session. It’s where you set fields such as your speech-to-text provider, initial messages,
etc. Here’s a simple example:
configure_session function, you can specify arbitrary fields that will be available throughout a
session, which is particularly useful if your LLM logic needs access to user-specific fields, like a
user ID. Here’s how you can make a my_user_id field available throughout a session:
configure_session function can also accept custom fields sent from wherever you start the
session. For example, here’s how you can pass in a my_user_timezone field:
configure_session function, see the Configuring
Sessions reference.
LLM responses
Thellm_response_handler function is responsible for returning the LLM’s response during a
session. It’s called every time a response is expected from the agent.
Here’s an example:
llm_response_handler, you can truncate the chat history, call a RAG pipeline, use any
LLM provider, or add any other logic that controls the LLM’s response.
The llm_response_handler can accept the custom fields that you define when configuring the
session. For example, if you specified a user ID field called my_user_id when configuring the
session, you can access it like this in your llm_response_handler:
Agent
The Agent is an object that contains all of your agent’s functionality.
The Agent below is the simplest possible agent. It contains the two functions defined above
(configure_session and llm_response_handler). It also contains your agent ID, which was
automatically added to the agent in the Quickstart guide.
Agent is also where you’ll define event handlers and function calls (i.e. tool calls), which
are covered in other guides.
For a complete list of fields on the Agent, see the Agent
reference.
Note: All of the logic related to your agent, including utility functions, must go in an
agent folder. This is required because Jay packages this logic into a container that we host
when you deploy your agent.
Next Steps
If you’re ready to connect your application to your agent, follow the Starting Sessions guide. Otherwise, if you want to add more functionality to your agent first, here are some guides to help:- Function Calling: Also known as “tool calling”, function calling lets you connect LLMs to external data and systems.
- Event Handlers: Event handlers are functions that react to events that occur throughout the lifecycle of a session. For example, an event is emitted every time the user starts talking.