Agent SDKInput & OutputStream Responses

Stream Responses

The Syntic Agent SDK does not make you wait for a final answer in silence. As Amara works, it emits a continuous stream of typed messages: assistant text as it is generated, notifications when a tool is called and when it returns, and a terminal result message that marks the end of the turn. Consuming this stream lets you render live progress and react to activity the moment it happens.

Both the TypeScript and Python entry points return an async iterable of messages. You inspect each message’s type to decide how to handle it.

Reading the message stream

Iterate the query and branch on message type. Assistant messages carry the model’s text, tool events describe actions, and the result message signals completion.

import { query } from "@syntic/agent-sdk";
 
for await (const message of query({ prompt: "Refactor utils.ts and explain what changed." })) {
  switch (message.type) {
    case "assistant":
      process.stdout.write(message.text);
      break;
    case "tool_use":
      console.log(`\n[calling ${message.name}]`);
      break;
    case "result":
      console.log(`\nDone (${message.durationMs}ms)`);
      break;
  }
}
async for message in query(prompt="Refactor utils.py and explain what changed."):
    if message.type == "assistant":
        print(message.text, end="")
    elif message.type == "tool_use":
        print(f"\n[calling {message.name}]")
    elif message.type == "result":
        print(f"\nDone ({message.duration_ms}ms)")

Text deltas and tool activity

Assistant text arrives incrementally, so you can stream it straight to a terminal or a UI without buffering the whole response. This is what produces the token-by-token feel of a live assistant. If you only need the finished text, ignore the intermediate deltas and read the accumulated content from the final assistant message.

Tool events let you show the user exactly what the agent is doing — which file it is reading, which command it is running — and their results let you display outcomes or errors inline. The single result message at the end carries the final answer along with metadata such as timing, token counts, and cost, which you can log or surface. For turning that final answer into typed data, see Structured Output.