adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
103 lines (102 loc) • 3.05 kB
TypeScript
import { Content } from '../models/types';
import { Event } from '../events/Event';
import { BaseAgent, AgentOptions } from './BaseAgent';
import { InvocationContext } from './InvocationContext';
/**
* Message types for LangGraph
*/
export interface Message {
type: 'human' | 'ai' | 'system';
content: string;
}
export interface HumanMessage extends Message {
type: 'human';
}
export interface AIMessage extends Message {
type: 'ai';
}
export interface SystemMessage extends Message {
type: 'system';
}
/**
* Interface for a CompiledGraph from LangGraph
*/
export interface CompiledGraph {
invoke: (input: {
messages: Message[];
}, config: any) => {
messages: Message[];
};
getState: (config: any) => {
values?: {
messages?: Message[];
};
};
checkpointer?: any;
}
/**
* Options for the LanggraphAgent.
*/
export interface LanggraphAgentOptions extends AgentOptions {
/** The LangGraph compiled graph */
graph: CompiledGraph;
/** The instruction to use as SystemMessage */
instruction?: string;
}
/**
* LangGraph agent implementation.
* Currently a concept implementation, supports single and multi-turn.
*/
export declare class LanggraphAgent extends BaseAgent {
/** The LangGraph compiled graph */
private readonly graph;
/** The instruction to use as SystemMessage */
private readonly instruction;
/**
* Creates a new LanggraphAgent.
*
* @param name The name of the agent
* @param options Options for the agent
*/
constructor(name: string, options: LanggraphAgentOptions);
/**
* Implementation of the agent's async invocation logic.
*
* @param ctx The invocation context
* @returns An async generator of events
*/
protected runAsyncImpl(ctx: InvocationContext): AsyncGenerator<Event, void, unknown>;
/**
* Implementation of the agent's live invocation logic.
*
* @param ctx The invocation context
* @returns An async generator of events
*/
protected runLiveImpl(ctx: InvocationContext): AsyncGenerator<Event, void, unknown>;
/**
* Sets the user content for the agent.
* This is a no-op for LanggraphAgent as it extracts content from session events.
*
* @param content The user content
* @param invocationContext The invocation context
*/
setUserContent(content: Content, invocationContext: InvocationContext): void;
/**
* Extracts messages from given list of events.
*
* If the developer provides their own memory within langgraph, we return the
* last user messages only. Otherwise, we return all messages between the user
* and the agent.
*
* @param events The list of events
* @returns List of messages
*/
private getMessages;
/**
* Extracts conversation messages from given list of events.
*
* @param events The list of events
* @returns List of messages
*/
private getConversationWithAgent;
}