@waldzellai/adk-typescript
Version:
TypeScript SDK for Google Agent Development Kit (ADK) - A comprehensive framework for building AI agents
162 lines (161 loc) • 6.03 kB
TypeScript
import { BaseAgent } from './agents/base_agent';
import { LlmAgent } from './agents/llm_agent';
import { InvocationContext } from './agents/invocation_context';
import { LiveRequestQueue, LiveRequest } from './agents/live_request_queue';
import { RunConfig } from './agents/run_config';
import { BaseArtifactService } from './artifacts/base_artifact_service';
import { Event } from './events/event';
import { BaseMemoryService } from './memory/base_memory_service';
import { BaseSessionService } from './sessions/base_session_service';
import { Session } from './sessions/session';
import { Content } from '@google/genai';
/**
* The Runner class is used to run agents.
*
* It manages the execution of an agent within a session, handling message
* processing, event generation, and interaction with various services like
* artifact storage, session management, and memory.
*/
export declare class Runner {
/** The application name of the runner. */
appName: string;
/** The root agent to run. */
agent: BaseAgent;
/** The artifact service for the runner. */
artifactService?: BaseArtifactService;
/** The session service for the runner. */
sessionService: BaseSessionService;
/** The memory service for the runner. */
memoryService?: BaseMemoryService;
constructor(options: {
appName: string;
agent: BaseAgent;
artifactService?: BaseArtifactService;
sessionService: BaseSessionService;
memoryService?: BaseMemoryService;
});
/**
* Runs the agent.
*
* NOTE: This sync interface is only for local testing and convenience purposes.
* Consider using `runAsync` for production usage.
*
* @param options.userId The user ID of the session.
* @param options.sessionId The session ID of the session.
* @param options.newMessage A new message to append to the session.
* @param options.runConfig The run config for the agent.
* @returns An array of events generated by the agent.
*/
run(options: {
userId: string;
sessionId: string;
newMessage: Content;
runConfig?: RunConfig;
}): Event[];
/**
* Main entry method to run the agent in this runner.
*
* @param options.userId The user ID of the session.
* @param options.sessionId The session ID of the session.
* @param options.newMessage A new message to append to the session.
* @param options.runConfig The run config for the agent.
* @returns An async generator yielding the events generated by the agent.
*/
runAsync(options: {
userId: string;
sessionId: string;
newMessage: Content;
runConfig?: RunConfig;
}): AsyncGenerator<Event, void, undefined>;
/**
* Creates a new invocation context.
*
* @param options Options for creating the invocation context
* @returns The new invocation context
*/
protected _newInvocationContext(options: {
agent: BaseAgent;
runConfig: RunConfig;
session: Session;
userContent: Content;
userId: string;
}): InvocationContext;
/**
* Creates a new invocation context for live execution.
*
* @param options Options for creating the live invocation context
* @returns The new live invocation context
*/
protected _newInvocationContextForLive(options: {
agent: BaseAgent;
runConfig: RunConfig;
session: Session;
requestQueue: LiveRequestQueue;
userId: string;
}): InvocationContext;
/**
* Appends a new message to the session and creates an event.
*
* @param context The invocation context
* @returns The created event
*/
protected _appendNewMessageToSession(context: InvocationContext): Promise<Event>;
/**
* Finds the appropriate agent to run based on the current state.
*
* @param context The invocation context
* @returns The agent to run
*/
protected _findAgentToRun(context: InvocationContext): BaseAgent;
/**
* Recursively searches for an agent by name in the agent tree.
*
* @param agent The current agent to check
* @param name The name to search for
* @returns The found agent or null if not found
*/
private _findAgentByName;
/**
* Checks if an agent can be transferred to across the agent tree.
*
* @param agentToCheck The agent to check
* @returns True if the agent can be transferred to, false otherwise
*/
protected _isTransferableAcrossAgentTree(agentToCheck: BaseAgent): boolean;
/**
* Closes the current session, performing cleanup as needed.
*
* @param sessionId The ID of the session to close
* @param userId The ID of the user
*/
closeSession(sessionId: string, userId: string): Promise<void>;
/**
* Runs the agent in live (streaming) mode.
*
* This method is designed for bidirectional streaming where the user can
* send multiple messages during an agent invocation, especially useful for
* processing real-time audio or other streaming data.
*
* @param options.userId The user ID of the session
* @param options.sessionId The session ID of the session
* @param options.runConfig The run configuration
* @param options.initialRequest The initial live request to send
* @returns An async generator yielding events generated by the agent
*/
runLive(options: {
userId: string;
sessionId: string;
runConfig?: RunConfig;
initialRequest?: LiveRequest;
}): AsyncGenerator<Event, void, undefined>;
}
/**
* An in-memory Runner for testing and development.
*
* This runner uses in-memory implementations for artifact, session, and memory
* services, providing a lightweight and self-contained environment for agent
* execution.
*/
export declare class InMemoryRunner extends Runner {
constructor(agent: LlmAgent, appName?: string);
}