UNPKG

@dexwox-labs/a2a-client

Version:

TypeScript client implementation for Google's Agent-to-Agent (A2A) protocol - includes HTTP/WebSocket communication, circuit breakers and error handling

89 lines 3.5 kB
/** * @module AgentClient * @description Client for interacting with A2A agents and their capabilities */ import { AgentCard } from '@dexwox-labs/a2a-core'; import { MessageClientOptions } from './types'; /** * Client for discovering and interacting with A2A agents * * @example * ```typescript * const agentClient = new AgentClient({ baseUrl: 'https://a2a-server.example.com' }); * * // Get all available agents * const agents = await agentClient.resolveAgents(); * * // Get a specific agent by ID * const agent = await agentClient.getAgentCard('weather-agent'); * ``` */ export declare class AgentClient { private options; /** @private Cache for agent resolution results */ private agentCache; /** @private Time-to-live for the agent cache in milliseconds */ private cacheTTL; /** * Creates a new AgentClient instance * @param options - Configuration options for the client */ constructor(options: MessageClientOptions); /** * Resolves agent cards with caching * * This method discovers available agents from the A2A server. Results are cached * to improve performance and reduce network traffic. The cache can be bypassed * by setting forceRefresh to true. * * @param capability - Optional capability filter to find agents with specific capabilities * @param forceRefresh - Whether to bypass the cache and force a fresh request (default: false) * @returns Promise resolving to an array of matching AgentCards * @throws {A2ANetworkError} If there's a network issue contacting the server * @throws {A2AValidationError} If the server response is invalid * @throws {A2ATimeoutError} If the request times out * * @example * ```typescript * // Get all agents * const allAgents = await agentClient.resolveAgents(); * * // Get only agents with a specific capability * const weatherAgents = await agentClient.resolveAgents('weather-forecasting'); * * // Force a fresh request bypassing the cache * const freshAgents = await agentClient.resolveAgents(undefined, true); * ``` */ resolveAgents(capability?: string, forceRefresh?: boolean): Promise<AgentCard[]>; /** * Gets a specific agent's card by ID * * This method retrieves information about a specific agent by its ID. It uses * the resolveAgents method internally and filters the results to find the * requested agent. * * @param agentId - The ID of the agent to look up * @param forceRefresh - Whether to bypass the cache and force a fresh request (default: false) * @returns Promise resolving to the requested AgentCard * @throws {A2AValidationError} If the agent with the specified ID is not found * @throws {A2ANetworkError} If there's a network issue contacting the server * @throws {A2ATimeoutError} If the request times out * * @example * ```typescript * try { * const weatherAgent = await agentClient.getAgentCard('weather-agent'); * console.log(`Found agent: ${weatherAgent.name}`); * } catch (error) { * if (error.code === 'VALIDATION_ERROR') { * console.error('Agent not found'); * } else { * console.error('Error fetching agent:', error.message); * } * } * ``` */ getAgentCard(agentId: string, forceRefresh?: boolean): Promise<AgentCard>; } //# sourceMappingURL=agent-client.d.ts.map