Agents
Sessions
Agents keep track of their conversations with sessions. One conversation is one session. To begin chatting with an agent, you need to create a session first. Each message sent by the user and each response from the agent is appended to the session. Sessions also provide a workspace for artifacts, allowing agents to work with uploaded documents and images throughout the conversation.
To inspect an existing conversation rather than create one, see Inspect agent runs. That guide covers the Debug drawer and View traces action.
This page covers operator sessions, created and read with an API key that can act across any of your customer's sessions. If you want to hand the session credential directly to an untrusted client, such as a browser tab or a mobile app, see End user sessions instead.
For a worked example that tests an agent from the terminal before embedding a widget, see Build an embedded agent with a widget connector.
Chat with your agent
After creating an agent, you can interact with it by creating a session and sending messages. Sessions provide conversation context and are required for all agent interactions.
Create a session (UI)
- Log into the Vectara Console.
- Open the Resources app and select Agents.
- Select an agent from the list such as Agent Research Assistant.
The agent opens the Preview tab.
- Chat with the agent in the Preview tab.
- Upload artifacts (files) to the session, and chat about these artifacts
with your agent.
You can continue to configure and fine tune the agent through the Configure tab.
Create a session (API)
- Send a
POSTrequest to the sessions endpoint.Create a session
Code example with multiple language options.1 - Once you have a session, send messages using the events endpoint:
Send a message
Code example with multiple language options.1
The agent will respond with events including its reasoning, tool usage, and final response.
You can also upload files (documents and images) to the session workspace using multipart requests. See Artifacts for details on working with files in agent sessions.
Define session context with session metadata
Let's say you want to make the agent aware of the user's preferred language, so that it can respond in that language. Or imagine you want to tell the agent that the user is only permitted access to a specific type of data. You can do all this with session metadata. Session metadata enables you to inject arbitrary information into the session context, which your instructions and tools can refer to.
Session metadata provides context-specific data to agents, enabling personalization, security controls, and dynamic behavior. This key-value data attaches to a session and becomes accessible as follows:
- Agent instructions (Velocity templates) using
${session.metadata.field}syntax - Tool configurations (argument overrides) using
{"$ref": "session.metadata.field"}syntax
Here's how you might implement the language preference and access control examples.
Example session with metadata
Session with comprehensive metadata
Code example with bash syntax.1
Then you'd write an instruction like this, to respond in the preferred language.
Instruction referencing session metadata
Code example with json syntax.1
And you'd configure a corpora search tool like this, to limit the user's access to certain corpora.
Passing per-user identity and downstream permissions
When your application authenticates users through SSO, the session is the right place to carry the identity data that downstream tools need. Your UI creates the session after authentication and writes the user's attributes into metadata and any per-user credential into secrets.
Create the session with the user's identity:
POST /v2/agents/{agent_key}/sessions
{
"metadata": {
"user_email": "alice@example.com",
"user_groups": "procurement,uk-employees"
},
"secrets": {
"workday_token": "<alice's Workday OAuth token>"
}
}
Put per-user credentials in secrets rather than metadata. Session metadata is returned in full on every read of the session. Session secrets are encrypted at rest and read back as "****". Masking covers API reads and session events. It does not cover a template that renders a secret, or a client tool that receives one in its arguments. See Secrets.
Reference the token from the tool's argument_override using $ref. The token resolves at call time from the session and is not exposed to the model.
{
"workday_lookup": {
"type": "web_get",
"argument_override": {
"auth": {
"type": "bearer",
"token": { "$ref": "session.secrets.workday_token" }
}
}
}
}
When the agent calls this tool on behalf of Alice, the downstream system receives Alice's token and returns only what Alice is permitted to see. Vectara does not replicate the downstream system's permission model. Enforcement happens at the call site. The same shape works for any system that accepts a per-user credential: substitute workday_token with the relevant secret name.
Scoping corpus search to the current user
For ingested data where ACL fields were written onto documents as metadata at ingest time, store a pre-built filter expression in session metadata and reference it from the corpora_search tool's query_configuration.
Create the session with the filter expression:
{
"metadata": {
"user_email": "alice@example.com",
"corpus_filter": "'alice@example.com' IN doc.acl_readers OR 'procurement' IN doc.acl_groups OR doc.acl_is_public = true"
}
}
Attach the expression to the corpus in query_configuration. The platform resolves the $ref from the session at the start of each turn. The filter is not exposed to the agent:
{
"knowledge_search": {
"type": "corpora_search",
"query_configuration": {
"search": {
"corpora": [{
"corpus_key": "company-knowledge",
"metadata_filter": { "$ref": "session.metadata.corpus_filter" }
}]
}
}
}
}
The filter is OR-shaped — any path that grants access lets the document through. The metadata filter limits which passages are returned by this search tool and made available as retrieved context for generation. For the full ABAC setup, see Attribute-based access control.
A $ref resolves a whole value, so the session metadata field has to hold the complete filter expression. Build access_filter server-side as doc.access_level = 'manager' rather than storing the role on its own and interpolating it into a larger expression.
Tool with metadata-based access control
Code example with json syntax.1