Matching the Tengu Chat experience

The Brain agent API spawns the same agent that powers Tengu Chat. Out of the box, a plain messages[] request already gives you fully-orchestrated, tool-using answers.

If you want the API to feel exactly like the chat product — same situational awareness, same tone, same instructions — you can optionally enrich each request with a few conventions. These are all things you add to the content you already send; no new endpoints, no extra parameters.

Everything on this page is optional. Skip it and Brain still works perfectly. Add it to mirror the chat UX.

1. Per-message page context#

In Tengu Chat, the agent knows what the user is looking at. You can give the API the same awareness by prepending a <page_context> block to each user message. Put whatever your app's current view represents — a ticker, a portfolio screen, a filing — so Brain grounds its answer in that context.

Python
1user_message = """<page_context>2view: ticker3symbol: NVDA4timeframe: 1M5</page_context>6 7How does this compare to its sector peers?"""8 9resp = client.chat.completions.create(10    model="brain",11    messages=[{"role": "user", "content": user_message}],12)

Send a fresh <page_context> block on each turn to reflect where the user currently is. The free-form contents are up to you — keys like view, symbol, and timeframe are just a convention.

2. First-turn system message#

To set persistent behavior — your product's voice, formatting rules, domain constraints — include a <system_message> block with your own instructions on the first turn of a conversation. This is the API analog of the chat product's system prompt.

Python
1first_turn = """<system_message>2You are the analyst assistant inside Acme Terminal.3Always answer in concise bullet points. Cite the data source for every claim.4Never give personalized investment advice.5</system_message>6 7<page_context>8view: watchlist9symbols: [NVDA, AMD, AVGO]10</page_context>11 12Which of these has the strongest recent momentum?"""13 14messages = [{"role": "user", "content": first_turn}]15resp = client.chat.completions.create(model="brain", messages=messages)

You only need the <system_message> block once, at the start. On later turns, keep sending <page_context> (if relevant) and the user's text. Because Brain is stateless per request, the <system_message> persists only as long as you keep it in the messages[] history you send back.

TypeScript example#

TypeScript
1const firstTurn = `<system_message>2You are the analyst assistant inside Acme Terminal.3Always answer in concise bullet points. Cite the data source for every claim.4</system_message>5 6<page_context>7view: ticker8symbol: TSLA9</page_context>10 11Summarize the latest 10-Q highlights.`;12 13const resp = await client.chat.completions.create({14  model: "brain",15  messages: [{ role: "user", content: firstTurn }],16});

3. (Advanced) Page state push#

For richer parity, you can push a structured page_state — a fuller snapshot of the user's current view (loaded rows, selected filters, visible chart range) — inside the same context block convention. Use it when a short <page_context> isn't enough to disambiguate what the user means by "this" or "these." Keep it compact; it counts toward token metering like any other content.

Python
1user_message = """<page_context>2view: screener3</page_context>4 5<page_state>6filters: { sector: "Semiconductors", mktcap_min: 50e9 }7visible_rows: [NVDA, AMD, AVGO, QCOM]8sort: { by: "1m_return", dir: "desc" }9</page_state>10 11Why is the top row outperforming the rest?"""

This is optional and additive — start with <page_context> and reach for <page_state> only when you need the extra precision.

Not available over the API: personal-portfolio readout#

In Tengu Chat, the agent can read the signed-in user's personal brokerage portfolio for personalized answers. This is platform-only and is NOT available to API customers.

API keys have no brokerage identity — there is no linked account for Brain to read. Any portfolio-style analysis you want over the API must be driven by data you supply (for example, holdings you pass in the message content or a <page_state> block). Brain will not, and cannot, fetch a personal portfolio for an API request.

Summary#

ConventionWherePurposeRequired?
<page_context>Each user messageTell Brain what the user is looking atOptional
<system_message>First turn onlyYour persistent instructions / voiceOptional
<page_state> (advanced)A user messageFuller structured snapshot of the current viewOptional
Personal-portfolio readoutPlatform-only; not available over the APIN/A

None of these change how you call the API — they're just structured content inside the messages you already send. See quickstart.md for the base request shape.