---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://segmentstream.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Agent SDK

Run a company agent that uses the workspace ontology as tools with each member’s permissions.

## What you can build

- [Run a company agent in the app](https://segmentstream.com/docs/sdk/agent#start-with-app-chat)

  Give it instructions and the workspace tools its members are allowed to use.

- [Evaluate a conversation](https://segmentstream.com/docs/launch-a-company-agent#turn-the-conversation-into-an-eval)

  Compare an answer to a known record and run the same case as different roles.

- [Add a messaging channel](https://segmentstream.com/docs/launch-a-company-agent#connect-a-production-telegram-bot)

  Connect a Telegram bot, pair it to a signed-in member and inspect a real turn.

## Start with app chat

In a linked workspace, scaffold the agent with the CLI. The channel choice below lets you test in the app before connecting an external messenger. Edit agent/agent/instructions.md with the job, the sources the agent should consult and when it should ask a person for help.

Terminal · workspace root

```
segmentstream agent init --channel none
```

## Choose the model and the tool surface

The starter's segmentstream.json supplies the model settings. Keep defaultTools off to start with the workspace tools. The extension in agent/agent/extensions/segmentstream.ts connects the ontology to each turn.

agent/agent/agent.ts

```
import { defineAgent, segmentstream } from "@segmentstream/agent";
import config from "../segmentstream.json";

export default defineAgent({
  defaultTools: false,
  model: segmentstream.model(config.models.chat),
  reasoning: "medium",
});
```

## Verify a tool call in preview

Commit the change and deploy a named preview. Open /agent in the preview app as a member and ask for a record you know. Compare its fields with the record in the app. Repeat with a member who lacks read permission. Use the launch guide for repeatable evals, production deployment and Telegram pairing.

Terminal · workspace root

```
segmentstream deploy --preview --preview-name agent-pilot
segmentstream previews show agent-pilot
```

## Selected API methods and types

### Configure the agent · `defineAgent`

Defines the agent configuration authored in \`agent.ts\`. Returns the same object, preserving its literal type, stamped with the brand the compiler requires: a plain object export is rejected. TypeScript checks the argument against {@link AgentDefinition}: any key outside that shape is a compile error. The compiler derives identity (the agent name) at compile time from \`manifest.agentId\` (the package name or app-root basename), so do not author a \`name\` field.

```
function defineAgent<TAgent extends AgentDefinition>(definition: ExactDefinition<TAgent, AgentDefinition>): DefinedAgent<TAgent>;
```

### Select a gateway model · `segmentstream`

```
const segmentstream: import("eve/extension").ExtensionHandle<{
    readonly "~standard": {
        readonly version: 1;
        readonly vendor: "segmentstream";
        readonly validate: (input: unknown) => {
            readonly value: import("./config.js").SegmentStreamAgentConfig;
            readonly issues?: undefined;
        } | {
            readonly issues: ReadonlyArray<import("./config.js").ConfigIssue>;
        };
        readonly types: {
            readonly input: import("./config.js").SegmentStreamAgentConfigInput;
            readonly output: import("./config.js").SegmentStreamAgentConfig;
        };
    };
}> & {
    model: typeof model;
    manifestOf: typeof manifestOf;
}
```

### Inspect the web channel contract · `webChannel`

The agent's own HTTP channel, which browsers talk to: a member, or a guest of a declared website, who shows an agent token from the ontology talks to the agent as themselves, in their own chat; every other request keeps the runtime's defaults (this deployment's own functions, local development). The runtime reads this channel only from the agent's \`agent/channels/eve.ts\`, whose name it fixes. It passes \`agent/segmentstream.json\`, whose \`limits\` the ontology counts the web's turns against: \`\`\`ts import { webChannel } from "@segmentstream/agent/web"; import config from "../../segmentstream.json"; export default webChannel({ config }); \`\`\`

```
function webChannel(options?: WebAuthOptions): import("eve/channels/eve").EveChannel;
```

[Launch a company agent](https://segmentstream.com/docs/launch-a-company-agent)

[Read as Markdown ↗](https://segmentstream.com/docs/sdk/agent.md)
