TypeScriptADK-TS

Events

Events are the fundamental unit of communication in ADK-TS — every message, tool call, and state change flows through the event system as your agent runs.

Every interaction with an ADK-TS agent produces a stream of Event objects. An event is an immutable record of one thing that happened during a run: a user message, an agent reply, a tool call, a tool result, or a state update. Your application consumes this stream to display responses, react to tool activity, and read state changes.

Event structure

Event extends LlmResponse and adds ADK-TS-specific metadata:

import { Event, EventActions } from "@iqai/adk";

// Fields on every Event
event.id; // unique 8-char identifier
event.invocationId; // ID shared by all events in one run
event.author; // "user" or the agent's name
event.timestamp; // seconds since Unix epoch
event.content; // { role, parts } payload — text, function calls, results
event.partial; // true while the LLM is still streaming this event
event.actions; // EventActions — state deltas, artifact updates, control signals
event.longRunningToolIds; // present when a tool is running in the background
event.branch; // dotted agent path for multi-agent hierarchies

Two helper methods let you inspect content without parsing parts manually:

event.getFunctionCalls(); // { name, args }[] — tool calls the agent wants to make
event.getFunctionResponses(); // { name, response }[] — results returned from tools
event.isFinalResponse(); // true when this event is ready to display

How events flow

The Runner drives this loop. It calls agent.runAsync(), collects every yielded event, appends it to the session, and re-emits it to your for await loop. When the agent is finished, the stream ends.

Quick start

runner.runAsync() returns an async generator. Iterate it to process events as they arrive:

import { AgentBuilder } from "@iqai/adk";

const { runner } = await AgentBuilder.create("assistant")
  .withModel("gemini-2.5-flash")
  .withInstruction("You are a helpful assistant.")
  .build();

const events = runner.runAsync({
  userId: "user-1",
  sessionId: "session-1",
  newMessage: { role: "user", parts: [{ text: "What is 2 + 2?" }] },
});

for await (const event of events) {
  if (event.isFinalResponse() && event.content?.parts?.[0]?.text) {
    console.log(event.content.parts[0].text);
  }
}

isFinalResponse() returns true when the event is not a streaming chunk, not a function call, and not a function response — meaning it is safe to display to the user.

Session history

Every event is appended to session.events in chronological order. Reading session.events after a run gives you a full, auditable trace of everything that happened — useful for debugging, replaying state, and building audit logs.

State changes travel inside event.actions.stateDelta. The Runner applies each delta to session.state as it processes events, so your agent's state is always up to date by the time you receive the event in your loop.

Next steps