Loading...
Loading...
Integrate PICA into an application using the OpenAI Agents SDK. Use when adding PICA tools to an OpenAI agent via @openai/agents, setting up PICA MCP with the OpenAI Agents SDK, or when the user mentions PICA with OpenAI Agents.
npx skill4agent add picahq/skills pica-openai-agents@picahq/mcpnpx{
"mcpServers": {
"pica": {
"command": "npx",
"args": ["@picahq/mcp"],
"env": {
"PICA_SECRET": "your-pica-secret-key"
}
}
}
}@picahq/mcpnpxPICA_SECRETPICA_SECRET=sk_test_...
OPENAI_API_KEY=sk-....env.local.env.example@openai/agentsMCPServerStdiopnpm add @openai/agents zod@openai/agentsMCPServerStdioAgentrunzodMCPServerStdiocommand: "npx"args: ["@picahq/mcp"]await mcpServer.connect()mcpServers: [mcpServer]run(agent, input, { stream: true })raw_model_stream_eventrun_item_stream_eventawait mcpServer.close()process.envenv: {
...(process.env as Record<string, string>),
PICA_SECRET: process.env.PICA_SECRET!,
}import { Agent, run, MCPServerStdio } from "@openai/agents";
const mcpServer = new MCPServerStdio({
name: "PICA MCP Server",
command: "npx",
args: ["@picahq/mcp"],
env: {
...(process.env as Record<string, string>),
PICA_SECRET: process.env.PICA_SECRET!,
},
});
await mcpServer.connect();
try {
const agent = new Agent({
name: "PICA Assistant",
model: "gpt-4o-mini",
instructions: "You are a helpful assistant.",
mcpServers: [mcpServer],
});
// Non-streaming
const result = await run(agent, "List my connected integrations");
console.log(result.finalOutput);
// Streaming
const streamResult = await run(agent, "List my connected integrations", {
stream: true,
});
for await (const event of streamResult) {
if (event.type === "raw_model_stream_event") {
const data = event.data as Record<string, unknown>;
if (data.type === "response.output_text.delta") {
process.stdout.write(data.delta as string);
}
}
}
await streamResult.completed;
} finally {
await mcpServer.close();
}ReadableStreamPythonChat{ type: "text", content: "..." }{ type: "tool_start", name: "tool_name", input: "..." }{ type: "tool_end", name: "tool_name", output: "..." }{ type: "error", content: "..." }data: [DONE]| Event Type | Purpose | Key Fields |
|---|---|---|
| Raw model token deltas | |
| Tool calls, outputs, messages | |
| Agent switched (handoff) | |
data.type === "response.output_text.delta"data.deltaitem.rawItem.type"function_call"call_idnamearguments"function_call_output"call_idoutputnameMap<call_id, name>run_item_stream_eventSet<call_id>tool_startresult.finalOutputfinalOutputconst input = messages.map((m: { role: string; content: string }) => ({
role: m.role as "user" | "assistant",
content: m.content,
}));
const result = await run(agent, input, { stream: true });@openai/agentszodOPENAI_API_KEY.env.localPICA_SECRET.env.local.env.exampleOPENAI_API_KEYPICA_SECRETMCPServerStdiocommand: "npx"args: ["@picahq/mcp"]process.envenvmcpServer.connect()mcpServers: [mcpServer]run(){ stream: true }result.completedresult.finalOutputcall_idnameSet<call_id>mcpServer.close()finally