{"_id":"@aaravjain/agentmesh","name":"@aaravjain/agentmesh","dist-tags":{"latest":"0.2.0"},"versions":{"0.2.0":{"name":"@aaravjain/agentmesh","version":"0.2.0","description":"Lightweight multi-agent orchestration for LLMs. Works with OpenAI and Anthropic. Pipeline → Router → Agent with priority short-circuits, session memory, and tool use.","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --clean","dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"tsc --noEmit"},"keywords":["ai","agents","multi-agent","llm","orchestration","openai","pipeline","agentic","workflow","routing"],"author":{"name":"Aarav Jain"},"license":"MIT","peerDependencies":{"@anthropic-ai/sdk":">=0.24.0","openai":">=4.0.0"},"peerDependenciesMeta":{"@anthropic-ai/sdk":{"optional":true},"openai":{"optional":true}},"devDependencies":{"@anthropic-ai/sdk":"^0.39.0","@types/node":"^22.0.0","openai":"^4.104.0","tsup":"^8.0.0","typescript":"^5.5.0"},"_id":"@aaravjain/agentmesh@0.2.0","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-r7eZNqRrURMVLQWr/wSIJ5ijyT4bMU148/3O8LJNyNnbLZ5dNc2SovwaMnkUkaqWzLeCZysr8waQF8FpyBSTfA==","shasum":"b61ea66fc81fb3e74ecdfc9c93cd516a83ab0cdc","tarball":"https://registry.npmjs.org/@aaravjain/agentmesh/-/agentmesh-0.2.0.tgz","fileCount":6,"unpackedSize":44374,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGBn3F4FvrpdNXiKQFI80Ri7XVTemoZtbfQuHxmXtR+6AiA9OyQo78tw2Lov+eWfy3PBkO8SUwJFpyL5E6dtf4Z3Uw=="}]},"_npmUser":{"name":"aaravjain","email":"jain.aarav.257@gmail.com"},"directories":{},"maintainers":[{"name":"aaravjain","email":"jain.aarav.257@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/agentmesh_0.2.0_1782026096109_0.5758651670722956"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-21T07:14:55.980Z","0.2.0":"2026-06-21T07:14:56.280Z","modified":"2026-06-21T07:14:56.467Z"},"maintainers":[{"name":"aaravjain","email":"jain.aarav.257@gmail.com"}],"description":"Lightweight multi-agent orchestration for LLMs. Works with OpenAI and Anthropic. Pipeline → Router → Agent with priority short-circuits, session memory, and tool use.","keywords":["ai","agents","multi-agent","llm","orchestration","openai","pipeline","agentic","workflow","routing"],"author":{"name":"Aarav Jain"},"license":"MIT","readme":"# agentmesh\n\n**The simplest way to build multi-agent LLM pipelines.**\n\nWorks with **OpenAI** and **Anthropic**. One pattern — Pipeline → Router → Agent — with smart routing, tool use, session memory, and priority short-circuits built in.\n\n```bash\nnpm install agentmesh\n```\n\n---\n\n## The problem with other frameworks\n\nLangChain has 500+ classes. CrewAI forces you into \"role play\" metaphors. OpenAI's Agents SDK only works with OpenAI.\n\nagentmesh gives you one thing: a pipeline that routes messages to the right agent, runs tool loops until done, and remembers the conversation. Nothing else.\n\n---\n\n## Quickstart — OpenAI\n\n```ts\nimport { Pipeline, Agent, OpenAIProvider } from 'agentmesh';\n\nconst pipeline = new Pipeline({\n  provider: new OpenAIProvider(process.env.OPENAI_API_KEY!),\n  model: 'gpt-4o-mini',\n});\n\npipeline\n  .addAgent(new Agent({\n    name: 'coder',\n    description: 'Writes and debugs code in any language',\n    systemPrompt: 'You are an expert software engineer. Write clean, working code.',\n  }))\n  .addAgent(new Agent({\n    name: 'researcher',\n    description: 'Answers research and factual questions',\n    systemPrompt: 'You are a thorough research assistant. Be clear and cite your reasoning.',\n  }));\n\nconst result = await pipeline.run('How do I debounce a function in JavaScript?');\nconsole.log(result.output);     // clean JS answer\nconsole.log(result.agentUsed);  // \"coder\"\n```\n\n## Quickstart — Anthropic\n\n```ts\nimport { Pipeline, Agent, AnthropicProvider } from 'agentmesh';\n\nconst pipeline = new Pipeline({\n  provider: new AnthropicProvider(process.env.ANTHROPIC_API_KEY!),\n  model: 'claude-haiku-4-5-20251001',\n});\n\n// same Agent/addAgent API — provider is the only difference\n```\n\n---\n\n## Core concepts\n\n### Providers\n\nSwap the provider to switch models. Both implement the same interface so your agent code never changes.\n\n```ts\nimport { AnthropicProvider, OpenAIProvider } from 'agentmesh';\n\nnew AnthropicProvider(process.env.ANTHROPIC_API_KEY!)\nnew OpenAIProvider(process.env.OPENAI_API_KEY!)\n```\n\nYou can also bring your own by implementing the `LLMProvider` interface — works with any API that supports chat + tool use.\n\n### Agents\n\nEach agent has a name, a description (used for routing), and a system prompt.\n\n```ts\nnew Agent({\n  name: 'support',\n  description: 'Handles billing, account, and subscription questions',\n  systemPrompt: 'You are a friendly support agent. Be concise and helpful.',\n  model: 'gpt-4o',           // override per-agent\n  maxIterations: 8,           // max tool-use loops (default: 5)\n  tools: [lookupUser],\n  triggerKeywords: ['billing', 'invoice', 'charge', 'subscription'],\n})\n```\n\n### Tools\n\nDefine a schema and an execute function. The agent calls your tool automatically when needed.\n\n```ts\nimport type { AgentTool } from 'agentmesh';\n\nconst getWeather: AgentTool = {\n  name: 'get_weather',\n  description: 'Get current weather for a city',\n  input_schema: {\n    type: 'object',\n    properties: {\n      city: { type: 'string', description: 'City name, e.g. Chicago' },\n    },\n    required: ['city'],\n  },\n  execute: async ({ city }) => {\n    const res = await fetch(`https://wttr.in/${city}?format=j1`);\n    return res.json();\n  },\n};\n```\n\n### Routing\n\nagentmesh picks the right agent in this order — fastest first:\n\n| Step | Method | LLM call? |\n|------|--------|-----------|\n| 1 | Priority keyword match | No |\n| 2 | Standard keyword match | No |\n| 3 | Single agent registered | No |\n| 4 | LLM-based routing decision | Yes (1 fast call) |\n\nMost real apps route via keywords and never pay for a routing call.\n\n### Priority short-circuit\n\nMark an agent `priority: true` and give it `triggerKeywords`. If any keyword matches the input, that agent runs immediately — before anything else, without an LLM routing call. Use this for emergencies, errors, or anything time-sensitive.\n\n```ts\nnew Agent({\n  name: 'emergency',\n  description: 'Handles urgent safety situations',\n  systemPrompt: 'The user needs immediate help. Give one clear instruction fast.',\n  priority: true,\n  triggerKeywords: ['emergency', 'urgent', 'help me now', 'crisis', 'call 911'],\n})\n```\n\n### Session memory\n\nPass the same `sessionId` across calls and agents share the full conversation history automatically.\n\n```ts\nconst sid = 'user-42';\n\nawait pipeline.run(\"I'm building a REST API in Express\", sid);\nawait pipeline.run('What was I just building?', sid);\n// → \"You were building a REST API in Express.\"\n\npipeline.clearSession(sid);\n```\n\n---\n\n## Full example: customer support pipeline with tools\n\n```ts\nimport { Pipeline, Agent, OpenAIProvider } from 'agentmesh';\nimport type { AgentTool } from 'agentmesh';\n\nconst lookupOrder: AgentTool = {\n  name: 'lookup_order',\n  description: 'Look up an order by its ID',\n  input_schema: {\n    type: 'object',\n    properties: {\n      order_id: { type: 'string', description: 'The order ID' },\n    },\n    required: ['order_id'],\n  },\n  execute: async ({ order_id }) => ({\n    id: order_id,\n    status: 'shipped',\n    eta: '2026-06-28',\n    carrier: 'FedEx',\n    tracking: '7489234892348',\n  }),\n};\n\nconst pipeline = new Pipeline({\n  provider: new OpenAIProvider(process.env.OPENAI_API_KEY!),\n  model: 'gpt-4o-mini',\n  debug: true,\n});\n\npipeline\n  .addAgent(new Agent({\n    name: 'escalation',\n    description: 'Handles angry or threatening customers',\n    systemPrompt: 'De-escalate calmly. Acknowledge frustration. Offer a concrete resolution.',\n    priority: true,\n    triggerKeywords: ['lawyer', 'lawsuit', 'furious', 'unacceptable', 'refund now'],\n  }))\n  .addAgent(new Agent({\n    name: 'orders',\n    description: 'Handles shipping, tracking, and order status questions',\n    systemPrompt: 'You are a helpful order support agent. Always look up the order before responding.',\n    tools: [lookupOrder],\n    triggerKeywords: ['order', 'shipping', 'tracking', 'package', 'delivery', 'where is'],\n  }))\n  .addAgent(new Agent({\n    name: 'general',\n    description: 'Handles all other customer service questions',\n    systemPrompt: 'You are a friendly and concise support agent.',\n  }));\n\nconst result = await pipeline.run(\"Where is my order #88291? It's been two weeks.\");\n\nconsole.log(`Agent:   ${result.agentUsed}`);\nconsole.log(`Routed:  ${result.routingReason}`);\nconsole.log(`Tools:   ${result.toolsUsed.join(', ')}`);\nconsole.log(`Time:    ${result.durationMs}ms`);\nconsole.log(result.output);\n```\n\n---\n\n## Bring your own provider\n\nImplement `LLMProvider` to use any API — Groq, Mistral, local Ollama, whatever:\n\n```ts\nimport type { LLMProvider, LLMResponse } from 'agentmesh';\n\nclass GroqProvider implements LLMProvider {\n  async chat({ model, system, messages, tools }): Promise<LLMResponse> {\n    // call your API here\n    return { text: '...', toolCalls: [], stopReason: 'end_turn' };\n  }\n\n  async submitToolResults({ model, system, messages, toolResults, tools }): Promise<LLMResponse> {\n    // submit tool results and get the next response\n    return { text: '...', toolCalls: [], stopReason: 'end_turn' };\n  }\n}\n\nconst pipeline = new Pipeline({\n  provider: new GroqProvider(),\n  model: 'llama-3.1-8b-instant',\n});\n```\n\n---\n\n## API reference\n\n### `new Pipeline(config)`\n\n| Option | Type | Required | Description |\n|--------|------|----------|-------------|\n| `provider` | `LLMProvider` | Yes | `AnthropicProvider` or `OpenAIProvider` |\n| `model` | `string` | Yes | Default model ID for all agents |\n| `sessionTtlMs` | `number` | No | Session expiry (default: 30 min) |\n| `onToken` | `(t: string) => void` | No | Called with each agent response |\n| `debug` | `boolean` | No | Log routing decisions to console |\n\n### `pipeline.run(message, sessionId?)`\n\nRoutes the message, runs the agent, returns:\n\n```ts\n{\n  output: string;        // the agent's response\n  agentUsed: string;     // which agent handled it\n  routingReason: string; // why it was routed there\n  toolsUsed: string[];   // tool names called\n  sessionId: string;     // pass this back to continue the conversation\n  durationMs: number;    // total wall time\n}\n```\n\n### `new Agent(config)`\n\n| Option | Type | Required | Description |\n|--------|------|----------|-------------|\n| `name` | `string` | Yes | Unique agent name |\n| `description` | `string` | Yes | Used by the LLM router to pick agents |\n| `systemPrompt` | `string` | Yes | The agent's instructions |\n| `tools` | `AgentTool[]` | No | Tools the agent can call |\n| `model` | `string` | No | Override the pipeline's default model |\n| `maxIterations` | `number` | No | Max tool-use loops (default: 5) |\n| `priority` | `boolean` | No | If true, checked first via keyword match |\n| `triggerKeywords` | `string[]` | No | Keywords that route to this agent without an LLM call |\n\n---\n\n## Why not LangChain / CrewAI / other?\n\n| | agentmesh | LangChain | CrewAI | OpenAI Agents SDK |\n|--|--|--|--|--|\n| Works with OpenAI | ✅ | ✅ | ✅ | ✅ |\n| Works with Anthropic | ✅ | ✅ | ✅ | ❌ |\n| Bring your own provider | ✅ | ✅ | ⚠️ | ❌ |\n| Lines to build a pipeline | ~15 | 50+ | 40+ | ~20 |\n| Priority short-circuit | ✅ | ❌ | ❌ | ❌ |\n| Session memory built-in | ✅ | ⚠️ | ❌ | ⚠️ |\n| Zero mandatory dependencies | ✅ | ❌ | ❌ | ❌ |\n\n---\n\n## License\n\nMIT — Aarav Jain\n","readmeFilename":"README.md","_rev":"1-d872aa2058a8a758ef973f566c4a4295"}