import type { AgentCard } from '@a2a-js/sdk'; import { AgentExecutor, ExecutionEventBus, RequestContext, TaskStore } from '@a2a-js/sdk/server'; import type { ImageContent } from '@earendil-works/pi-ai'; import { z } from 'zod/v4'; import type { PSAgentConfigWithLocal } from './PSAgentConfig'; import { IStreamLogger } from './PSAgentLogger'; import { PSAgentTask } from './PSAgentTask'; import { IPSAgentToolResult, PSAgentTool } from './PSAgentTool'; import { Agent } from './agent-core/src/agent.js'; import type { AgentEvent, AgentMessage, AgentState, QueueMode } from './agent-core/src/types.js'; export interface ServiceUrls { agents?: string; events?: string; llmtrack?: string; /** Base URL for the PS LLM API. Used in local mode to route LLM calls in-process. * e.g. 'https://dev.lionis.ai' — the /api/v1/llm path is appended automatically. * Defaults to the agents service base URL when not specified. */ llm?: string; } export declare function sleep(ms: number): Promise; /** * PSAgent class to manage AI agents with tools and tasks * Implements AgentExecutor interface from A2A SDK * Supports starting, resuming, cancelling agents and executing tools * Manages agent state, tools, tasks and interactions with A2A platform * Includes methods for A2A server setup and event fetching * * uses the token from config if not PS_API_TOKEN env variable * adds x-client-id, x-project-id, x-workspace-id from env variables * PS_CLIENT_ID, PS_PROJECT_ID, PS_WORKSPACE_ID respectively for authentication headers * * @example * ```typescript * import { PSAI, PSAgent, PSAgentLogger } from 'psadk'; * import dotenv from 'dotenv'; * dotenv.config(); * async function main() { * const token = await PSAI.getServiceToken({}); * const HelloAgent = new PSAgent({ * name: 'HelloAgent', * description: 'A simple hello world agent', * system_prompt: 'You are a helpful assistant that greets users.', * model: 'gpt-5', * tools: [], * log: new PSAgentLogger({ level: 'info' }), * token: token, * port: 41241, * }); * const { app, port } = HelloAgent.getA2AServer(); * app.listen(port, () => { * console.log('HelloAgent is running on http://localhost:${port}'); * }); * } * main(); * ``` * @see PSAgentConfig, PSAgentTool, PSAgentTask * * @see * https://dev.lionis.ai/docs/api/v1/agents/create-agent * https://pscode.lioncloud.net/ai-tso/psadk_samples * https://a2aproject.com/docs/getting-started/quickstart * */ export declare class PSAgent implements AgentExecutor { config: PSAgentConfigWithLocal; private tools; private tasks; private agentId?; private correlationId?; private readonly log?; private serviceUrls?; private cancelledTasks; /** * Internal local-mode support module. * Only populated when `config.local === true`. * @internal */ /** agent-core Agent instance. Only set when config.local === true. */ private localCoreAgent?; cancelTask: (taskId: string) => Promise; /** * create a new PSAgent with the given config * @param config PSAgentConfig with optional logger * @param services Optional service URLs - can be a string (legacy) or ServiceUrls object */ constructor(config: PSAgentConfigWithLocal, services?: ServiceUrls); /** * Get the Agent Class * @returns Agent class from config or default "LlmAgent" */ get AgentClass(): string; /** * Get the Name of the Agent * * @returns Name of the agent from config */ get Name(): string; /** * Get the Description of the Agent * @returns Description of the agent from config */ get Description(): string; /** * Get the Instruction(System Prompt) of the Agent * @returns Instruction(System prompt) of the agent from config */ get Instruction(): string; /** * Get the Model of the Agent * @returns Model of the agent from config */ get Model(): string | undefined; /** * Get the Input Schema of the Agent * @returns Input schema of the agent from config */ get InputSchema(): z.core.JSONSchema.BaseSchema | undefined; /** * Get the Output Schema of the Agent * @returns Output schema of the agent from config */ get OutputSchema(): z.core.JSONSchema.BaseSchema | undefined; /** * Get the Token for the Agent * @returns Token of the agent from config */ get Token(): string | undefined; /** * Set the Token for the Agent * @param value Token string to set in config */ set Token(value: string | undefined); /** * Get the Tools for the Agent * Includes both config tools and dynamically added tools * @returns Array of PSAgentTool instances */ get Tools(): PSAgentTool[]; /** * Get the Tasks for the Agent * Includes both config tasks and dynamically added tasks * @returns Array of PSAgentTask instances */ get Tasks(): PSAgentTask[]; /** * Get the Agent ID after starting the agent * @returns Agent ID string or undefined if not started */ get AgentId(): string | undefined; /** * Set the Agent ID after starting the agent * @param value Agent ID string to set */ set AgentId(value: string | undefined); /** * Get the Correlation ID after starting the agent * @returns Correlation ID string or undefined if not started */ get CorrelationId(): string | undefined; /** * Set the Correlation ID after starting the agent * @param value Correlation ID string to set */ set CorrelationId(value: string | undefined); get Config(): PSAgentConfigWithLocal; /** * Add tools to the agent dynamically * @param tool PSAgentTool to add to the agent */ addTool(tool: PSAgentTool): void; private getToken; private getAuthHeaders; private getBaseUrl; /** * start a new temp agent on the agent platform * @param input input to the agent the schema should match InputSchema if provided * @param history history of messages for agent context * @param log logger to use for logging, defaults to agent's logger * @returns Correlation ID of the started agent */ start(input: object, history?: any[], log?: IStreamLogger): Promise; /** * * @param instruction instruction for the agent * @returns */ instruct(instruction: string): Promise>; /** * resume the agent with tool output after a tool execution or human input * @param tooloutput output from the tool execution to send back to the agent * @returns */ resume(tooloutput: Record): Promise>; /** * deletes the agent running on the platform * @param log optional logger to use for logging, defaults to agent's logger */ cancel(log?: IStreamLogger): Promise; /** * Gets all the events for the current agent run identified correlation ID * @returns Array of event objects for the current agent's correlation ID * @see https://dev.lionis.ai/api/v1/events/events?correlationId={{correlation_id}} */ getEvents(): Promise>>; /** * Fetch evaluation data for the agent using the agent ID * @returns Promise containing the evaluation data as a Record * @throws Error if agent ID is not set or if the fetch operation fails * * @example * ```typescript * const agent = new PSAgent(config); * // ... after agent execution ... * const evaluationData = await agent.getEvaluationData(); * console.log('Evaluation results:', evaluationData); * ``` */ getEvaluationData(): Promise>; /** * Invoke the tool with the given name and input * @remarks * The input object should match the tool's input schema * * @param toolName name of the tool to execute * @param input input object for the tool execution should match tool's input schema * @param log logger to use for logging, defaults to agent's logger * @returns output from the tool execution or error if any * * @example * Example input for PSArtifactTool: * ```json * { * "name": "example_artifact", * "action": "write", * "content": "This is an example artifact content." * } * ``` */ executeTool(toolName: string, input: Record, log?: IStreamLogger): Promise; private getHostIPAddress; /** * Port for A2A express server * @returns Port number from config or default 41241 */ private getPort; /** * get A2A express server app * @param taskStore Optional TaskStore, defaults to InMemoryTaskStore * @returns A2A Express app */ getA2AServer(taskStore?: TaskStore): { app: import("express-serve-static-core").Express; port: number; }; getAgentCard(): AgentCard; static FromConfigFile(config_path: string): PSAgent; private _assertLocal; /** The underlying agent-core Agent. Only set when local: true. */ get localAgent(): Agent | undefined; /** Prompt the local Agent. @throws if not in local mode. */ prompt(input: string | AgentMessage | AgentMessage[], images?: ImageContent[]): Promise; /** Continue from the current transcript. @throws if not in local mode. */ continueLocal(): Promise; /** Abort the in-flight run. @throws if not in local mode. */ abortLocal(): void; /** Resolve when the current run settles. @throws if not in local mode. */ waitForLocalIdle(): Promise; /** Reset the transcript and queues. @throws if not in local mode. */ resetLocal(): void; /** Queue a steering message. @throws if not in local mode. */ steerLocal(message: AgentMessage): void; /** Queue a follow-up message. @throws if not in local mode. */ followUpLocal(message: AgentMessage): void; /** Subscribe to lifecycle events. @throws if not in local mode. */ subscribeLocal(listener: (event: AgentEvent, signal: AbortSignal) => Promise | void): () => void; /** Read-only view of the current agent state. Only set when local: true. */ get localState(): AgentState | undefined; set localSteeringMode(mode: QueueMode); get localSteeringMode(): QueueMode | undefined; set localFollowUpMode(mode: QueueMode); get localFollowUpMode(): QueueMode | undefined; /** * A2A AgentExecutor entry point. * * When `config.local === true` the call is routed to the local support module. * Otherwise the original remote platform path is used. */ execute(requestContext: RequestContext, eventBus: ExecutionEventBus): Promise; }