An easy to use SDK for creating Agent2Agent (A2A) agents.
npm install @artinet/a2aAn easy-to-use SDK for creating Agent2Agent (A2A) agents with OpenAI-compatible APIs.
@artinet/a2a provides a fluent builder for constructing multi-step AI agents with type-safe composition and automatic execution orchestration. Build agents that can communicate with other agents and easily manage complex multi-agent interactions.
``bash`
npm install @artinet/a2a
`typescript
import { AIAgentBuilder } from "@artinet/a2a";
// Create an AI agent with OpenAI
const agent = AIAgentBuilder({ apiKey: "your-api-key" })
.ai("You are a helpful assistant.")
.createAgent({
agentCard: "MyAgent",
});
// Send a message
const result = await agent.sendMessage("Hello!");
`
- Fluent Builder API: Define your agents behaviour with chainable methods
- Multi-Agent Orchestration: Connect to other agents via the AgentRelay.
- Tool Integration: Automatically convert A2A agents into OpenAI-compatible function tools
- Executor Conversion: Convert A2A executors into AgentEngine for advanced workflows
`typescript
import { AgentBuilder, getContent } from "@artinet/sdk";
import { AIAgentBuilder } from "@artinet/a2a";
// Create helper agents
const echoAgent = AgentBuilder()
.text(({ content }) => content ?? "No content")
.createAgent({ agentCard: "EchoAgent" });
const testAgent = AgentBuilder()
.text(({ content }) => "You have successfully reached the test agent.")
.createAgent({ agentCard: "TestAgent" });
// Expose them to your AI Agent
const aiAgent = AIAgentBuilder(
{ apiKey: "your-api-key" },
{
callerId: "main-agent",
agents: new Map([
["echo-agent", echoAgent],
["test-agent", testAgent],
]),
}
)
.text(() => "Message Recieved")
.ai("Use your agents to fulfill the request.")
.createAgent({ agentCard: "MainAgent" });
// The AI agent can now call or be called by other A2A agents
console.log(
getContent(
await aiAgent.sendMessage("Call the test agent and tell me what it says")
)
);
`
Response:
`bash
I have access to the test agent and sent a message to it. The test agent responded, saying:
"You have successfully reached the test agent."
`
Creates a new agent builder with an OpenAI client and optional agent relay.
Parameters:
- client: OpenAI instance or ClientOptionsagents?
- : AgentRelay, AgentRelayConfig, or A2AClient, Agent for multi-agent communication
Adds an AI step to the agent workflow.
Parameters:
- body: System prompt string or full ChatCompletionCreateParamsoptions?
- : Request options including history/args/content inclusion settings
Converts an AgentExecutor(from @a2a-js/sdk) into an AgentEngine`.
Apache-2.0