Skip to content

Conversational agents ​

A conversational agent answers messages in a conversation. It keeps the history, can search knowledge, call tools and stream its answers. Use it for support chatbots and domain assistants.

Configure the agent ​

SettingPurpose
modela chat model (with tools capability if the agent uses tools or knowledge in tool mode)
instructionsthe system prompt: role, tone, what to do and not do
memory.historyMessageshow many previous messages are sent with each turn (0 to 200, default 20)
memory.summarizefold messages older than the history window into a running summary (default false)
memory.generateTitlegenerate a short title for new conversations (default true)
dataSourcesknowledge to search; knowledgeMode tool (default) or context
rewriteQueryin context mode, rewrite the message into a standalone search query using the history
tools, maxToolCallstools the model may call and the maximum number of calls per turn (default 10)

Each message is one run. Its output is always { "text": "..." }.

With memory.summarize, long conversations keep their context without sending every message: messages that fall out of the history window are merged into a summary (incrementally, by the agent's model, metered on the run that does it), and the summary is added to the instructions of each turn.

Two ways to talk to it ​

Conversations API ​

Create a conversation, then send messages to it. This is the natural fit for a chat UI that lists an end user's conversations.

bash
# 1. create (scope agents:run)
curl "$HEVKAR_BASE_URL/v1/conversations" \
  -H "Authorization: Bearer $HEVKAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent": "helpdesk", "externalUserId": "user_42", "metadata": {"plan": "pro"}}'

# 2. send a message (scope agents:run)
curl "$HEVKAR_BASE_URL/v1/conversations/$CONVERSATION_ID/messages" \
  -H "Authorization: Bearer $HEVKAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content": "Where is my order?"}'
ts
const conv = await hevkar.conversations.create({ agent: 'helpdesk', externalUserId: 'user_42' });

const reply = await hevkar.conversations.send(conv.id, { content: 'Where is my order?' });
console.log(reply.output); // { text: 'Could you give me your order number?' }

const next = await hevkar.conversations.send(conv.id, { content: 'It is A-1001' });
ts
const headers = { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' };
const conv = await fetch(`${baseUrl}/v1/conversations`, {
  method: 'POST',
  headers,
  body: JSON.stringify({ agent: 'helpdesk', externalUserId: 'user_42' }),
}).then((r) => r.json());

const reply = await fetch(`${baseUrl}/v1/conversations/${conv.id}/messages`, {
  method: 'POST',
  headers,
  body: JSON.stringify({ content: 'Where is my order?' }),
}).then((r) => r.json());

The reply is a RunResult with conversationId set. Messages always use the agent's current published version.

Runs API ​

You can also call the agent like any other agent with input.message. Without a conversationId a new conversation is created and its id is returned in the result; pass it back to continue:

ts
const first = await hevkar.agents.run('helpdesk', {
  input: { message: 'Hi, I need help with an invoice' },
  externalUserId: 'user_42',
});
const second = await hevkar.agents.run('helpdesk', {
  input: { message: 'The number is RE-118' },
  conversationId: first.conversationId,
});

This route supports everything a run supports: version pinning, async, metadata and the Idempotency-Key header. A missing or empty input.message answers 400 INPUT_INVALID.

Streaming replies ​

Send stream: true to receive the answer as Server-Sent Events:

bash
curl -N "$HEVKAR_BASE_URL/v1/conversations/$CONVERSATION_ID/messages" \
  -H "Authorization: Bearer $HEVKAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content": "And the tracking number?", "stream": true}'
ts
const stream = hevkar.conversations.send(conv.id, {
  content: 'And the tracking number?',
  stream: true,
});
for await (const e of stream) {
  if (e.event === 'text.delta') process.stdout.write(e.data.text);
}
const result = await stream.finalResult();

Files in messages ​

Pass uploaded file ids with a message (files: [id], up to 20). They are checked against the agent's files settings and stored with the user message. See Files.

History and listing ​

ts
// one conversation with its messages (scope runs:read)
const c = await hevkar.conversations.get(conv.id);
// c.messages: [{ id, role: 'user' | 'assistant', content: { text, files? }, runId, createdAt }]

// an end user's conversations, newest first
const page = await hevkar.conversations.list({ externalUserId: 'user_42', limit: 20 });
for await (const item of hevkar.conversations.listAll({ externalUserId: 'user_42' })) {
  // every page
}

// delete a conversation and its messages (runs keep their own record)
await hevkar.conversations.delete(conv.id);

The title is generated from the first message when memory.generateTitle is on.

Knowledge in conversations ​

  • Tool mode (default): the model gets a search_knowledge tool and decides when to search. Sources come back numbered so the answer can cite them as [1].
  • Context mode: every turn retrieves with the user's message and adds the numbered sources to the instructions. Turn on rewriteQuery so follow-ups like "and in Berlin?" become standalone queries (the rewrite uses the last few messages and its tokens count for the run).

Every retrieval is recorded in the run's retrieval field. See Knowledge.

Hevkar public API v1