HN 표시: Open-agent-SDK – Claude Code의 내부, 추출 및 오픈 소스
hackernews
|
|
📰 뉴스
#ai
#ai 딜
#anthropic
#claude
#sdk
#에이전트
#오픈소스
원문 출처: hackernews · Genesis Park에서 요약 및 분석
요약
클로드 코드(Claude Code)의 내부 기술이 추출되어 '오픈 에이전트 SDK(Open-agent-SDK'라는 이름의 오픈소스로 공개되었습니다. 이 SDK는 서브프로세스나 CLI 없이 프로세스 내에서 전체 에이전트 루프를 실행할 수 있도록 설계되어 클라우드, 서버리스, CI/CD 환경 등 어디든 배포가 가능합니다. 사용자는 34개의 기본 내장 툴을 활용하거나 Zod를 활용해 커스텀 도구를 제작할 수 있으며, 오픈루터(OpenRouter) 같은 서드파티 제공자도 지원됩니다. 또한 읽기 전용 모드 설정, 멀티 에이전트 간의 협업, 세션 유지 및 분기(Fork) 기능을 포함하여 복잡한 AI 작업을 매우 유연하게 제어할 수 있는 것이 특징입니다.
본문
Open-source Agent SDK that runs the full agent loop in-process — no subprocess or CLI required. Deploy anywhere: cloud, serverless, Docker, CI/CD. Also available in Go: open-agent-sdk-go npm install @codeany/open-agent-sdk Set your API key: export CODEANY_API_KEY=your-api-key Third-party providers (e.g. OpenRouter) are supported via CODEANY_BASE_URL : export CODEANY_BASE_URL=https://openrouter.ai/api export CODEANY_API_KEY=sk-or-... export CODEANY_MODEL=anthropic/claude-sonnet-4 import { query } from "@codeany/open-agent-sdk"; for await (const message of query({ prompt: "Read package.json and tell me the project name.", options: { allowedTools: ["Read", "Glob"], permissionMode: "bypassPermissions", }, })) { if (message.type === "assistant") { for (const block of message.message.content) { if ("text" in block) console.log(block.text); } } } import { createAgent } from "@codeany/open-agent-sdk"; const agent = createAgent({ model: "claude-sonnet-4-6" }); const result = await agent.prompt("What files are in this project?"); console.log(result.text); console.log( `Turns: ${result.num_turns}, Tokens: ${result.usage.input_tokens + result.usage.output_tokens}`, ); import { createAgent } from "@codeany/open-agent-sdk"; const agent = createAgent({ maxTurns: 5 }); const r1 = await agent.prompt( 'Create a file /tmp/hello.txt with "Hello World"', ); console.log(r1.text); const r2 = await agent.prompt("Read back the file you just created"); console.log(r2.text); console.log(`Session messages: ${agent.getMessages().length}`); import { z } from "zod"; import { query, tool, createSdkMcpServer } from "@codeany/open-agent-sdk"; const getWeather = tool( "get_weather", "Get the temperature for a city", { city: z.string().describe("City name") }, async ({ city }) => ({ content: [{ type: "text", text: `${city}: 22°C, sunny` }], }), ); const server = createSdkMcpServer({ name: "weather", tools: [getWeather] }); for await (const msg of query({ prompt: "What is the weather in Tokyo?", options: { mcpServers: { weather: server } }, })) { if (msg.type === "result") console.log(`Done: $${msg.total_cost_usd?.toFixed(4)}`); } import { createAgent, getAllBaseTools, defineTool, } from "@codeany/open-agent-sdk"; const calculator = defineTool({ name: "Calculator", description: "Evaluate a math expression", inputSchema: { type: "object", properties: { expression: { type: "string" } }, required: ["expression"], }, isReadOnly: true, async call(input) { const result = Function(`'use strict'; return (${input.expression})`)(); return `${input.expression} = ${result}`; }, }); const agent = createAgent({ tools: [...getAllBaseTools(), calculator] }); const r = await agent.prompt("Calculate 2**10 * 3"); console.log(r.text); import { createAgent } from "@codeany/open-agent-sdk"; const agent = createAgent({ mcpServers: { filesystem: { command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"], }, }, }); const result = await agent.prompt("List files in /tmp"); console.log(result.text); await agent.close(); import { query } from "@codeany/open-agent-sdk"; for await (const msg of query({ prompt: "Use the code-reviewer agent to review src/index.ts", options: { agents: { "code-reviewer": { description: "Expert code reviewer", prompt: "Analyze code quality. Focus on security and performance.", tools: ["Read", "Glob", "Grep"], }, }, }, })) { if (msg.type === "result") console.log("Done"); } import { query } from "@codeany/open-agent-sdk"; // Read-only agent — can only analyze, not modify for await (const msg of query({ prompt: "Review the code in src/ for best practices.", options: { allowedTools: ["Read", "Glob", "Grep"], permissionMode: "dontAsk", }, })) { // ... } A built-in web chat interface is included for testing: npx tsx examples/web/server.ts # Open http://localhost:8081 | Function | Description | |---|---| query({ prompt, options }) | One-shot streaming query, returns AsyncGenerator | createAgent(options) | Create a reusable agent with session persistence | tool(name, desc, schema, handler) | Create a tool with Zod schema validation | createSdkMcpServer({ name, tools }) | Bundle tools into an in-process MCP server | defineTool(config) | Low-level tool definition helper | getAllBaseTools() | Get all 34 built-in tools | listSessions() | List persisted sessions | getSessionMessages(id) | Retrieve messages from a session | forkSession(id) | Fork a session for branching | | Method | Description | |---|---| agent.query(prompt) | Streaming query, returns AsyncGenerator | agent.prompt(text) | Blocking query, returns Promise | agent.getMessages() | Get conversation history | agent.clear() | Reset session | agent.interrupt() | Abort current query | agent.setModel(model) | Change model mid-session | agent.setPermissionMode(mode) | Change permission mode | agent.close() | Close MCP connections, persist session | | Option | Type | Default | Description | |---|---|---|---| model | string | claude-sonnet-4-6 | LLM model ID | apiKey | string | CO
Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.
공유