adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
192 lines (191 loc) • 7.1 kB
TypeScript
import { BaseAgent } from './agents/BaseAgent';
import { LlmAgent } from './agents/LlmAgent';
import { LiveRequestQueue } from './agents/LiveRequestQueue';
import { RunConfig } from './agents/RunConfig';
import { BaseArtifactService } from './artifacts/BaseArtifactService';
import { Event } from './events/Event';
import { BaseMemoryService } from './memory/BaseMemoryService';
import { Content } from './models/types';
import { BaseSessionService } from './sessions/BaseSessionService';
import { Session } from './sessions/Session';
/**
* 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;
/**
* Initializes the Runner.
*
* @param params The parameters for the runner.
* @param params.appName The application name of the runner.
* @param params.agent The root agent to run.
* @param params.artifactService The artifact service for the runner.
* @param params.sessionService The session service for the runner.
* @param params.memoryService The memory service for the runner.
*/
constructor(params: {
appName: string;
agent: BaseAgent;
artifactService?: BaseArtifactService;
sessionService: BaseSessionService;
memoryService?: BaseMemoryService;
});
/**
* Runs the agent.
*
* NOTE: This sync interface is only for local testing and convenience purpose.
* Consider using `runAsync` for production usage.
*
* @param params The parameters for the run.
* @param params.userId The user ID of the session.
* @param params.sessionId The session ID of the session.
* @param params.newMessage A new message to append to the session.
* @param params.runConfig The run config for the agent.
* @returns A generator that yields the events generated by the agent.
*/
run(params: {
userId: string;
sessionId: string;
newMessage: Content;
runConfig?: RunConfig;
}): AsyncGenerator<Event, void, unknown>;
/**
* Main entry method to run the agent in this runner.
*
* @param params The parameters for the run.
* @param params.userId The user ID of the session.
* @param params.sessionId The session ID of the session.
* @param params.newMessage A new message to append to the session.
* @param params.runConfig The run config for the agent.
* @returns An async generator that yields events generated by the agent.
*/
runAsync(params: {
userId: string;
sessionId: string;
newMessage: Content;
runConfig?: RunConfig;
}): AsyncGenerator<Event, void, unknown>;
/**
* Appends a new message to a session.
*
* @param params The parameters for appending a message.
* @param params.session The session to append to.
* @param params.newMessage The message to append.
* @param params.invocationContext The invocation context.
* @param params.saveInputBlobsAsArtifacts Whether to save input blobs as artifacts.
* @private
*/
private _appendNewMessageToSession;
/**
* Runs the agent in live mode.
*
* @param params The parameters for live mode.
* @param params.session The session to use.
* @param params.liveRequestQueue The queue for live requests.
* @param params.runConfig The run config for the agent.
* @returns An async generator of events.
*
* @experimental This feature is **experimental** and its API or behavior may change
* in future releases.
*/
runLive(params: {
session: Session;
liveRequestQueue: LiveRequestQueue;
runConfig?: RunConfig;
}): AsyncGenerator<Event, void, unknown>;
/**
* Closes a session and adds it to the memory service.
*
* @param session The session to close.
* @experimental This feature is **experimental** and its API or behavior may change
* in future releases.
*/
closeSession(session: Session): Promise<void>;
/**
* Finds the agent to run to continue the session.
*
* A qualified agent must be either of:
* - The root agent;
* - An LlmAgent who replied last and is capable to transfer to any other agent
* in the agent hierarchy.
*
* @param session The session to find the agent for.
* @param rootAgent The root agent of the runner.
* @returns The agent of the last message in the session or the root agent.
* @private
*/
private _findAgentToRun;
/**
* Whether the agent to run can transfer to any other agent in the agent tree.
*
* This typically means all agent_to_run's parent through root agent can
* transfer to their parent_agent.
*
* @param agentToRun The agent to check for transferability.
* @returns True if the agent can transfer, False otherwise.
* @private
*/
private _isTransferableAcrossAgentTree;
/**
* Creates a new invocation context.
*
* @param params The parameters for the invocation context.
* @param params.session The session for the context.
* @param params.newMessage The new message for the context.
* @param params.liveRequestQueue The live request queue for the context.
* @param params.runConfig The run config for the context.
* @returns The new invocation context.
* @private
*/
private _newInvocationContext;
/**
* Creates a new invocation context for live multi-agent.
*
* @param params The parameters for the invocation context.
* @param params.session The session for the context.
* @param params.liveRequestQueue The live request queue for the context.
* @param params.runConfig The run config for the context.
* @returns The new invocation context.
* @private
*/
private _newInvocationContextForLive;
}
/**
* 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 {
/**
* Initializes the InMemoryRunner.
*
* @param agent The root agent to run.
* @param appName The application name of the runner. Defaults to 'InMemoryRunner'.
*/
constructor(agent: LlmAgent, appName?: string);
}