{"id":"7b0f929b-6a77-450b-802c-dd4173706a89","slug":"coagent-ai","kind":"mcp","name":"Coagent-AI","summary":"","owner":"Amayuru1999","repoUrl":"https://github.com/Amayuru1999/Coagent-AI","license":"AGPL-3.0","licenseTier":"strong-copyleft","trust":"community","stars":0,"match":null,"fewStars":true,"format":"mcp","createdAt":"2025-02-23T17:56:35.000Z","addedAt":"2026-10-21T18:27:06.257Z","logoUrl":"https://avatars.githubusercontent.com/u/116435706?u=daa9948bdebdcf49f157780f494b8656a608b03a&v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["utilities"],"tags":[],"runtime":"python","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-24T11:50:05.257Z","sample":false,"url":"https://conduits.dev/tools/coagent-ai","language":"Python","transports":["stdio"],"install":{"pypi":"coagent"},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"# Coagent\n[![CI](https://github.com/OpenCSGs/coagent/actions/workflows/ci.yml/badge.svg)](https://github.com/OpenCSGs/coagent/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)\n\nAn open-source framework for building monolithic or distributed agentic systems, ranging from simple LLM calls to compositional workflows and autonomous agents.\n\n\n<p align=\"center\">\n<img src=\"assets/coagent-overview.png\" height=\"600\">\n</p>\n\n\n## Latest Updates\n\n- 🚀 **2025-02-08**: Added support for [DeepSeek-R1](https://api-docs.deepseek.com/news/news250120), check out the [example](examples/deepseek-r1).\n- **2025-01-28**: Added support for [Structured Outputs][2].\n- **2025-01-22**: Added support for [Model Context Protocol][3].\n- **2025-01-17**: Added integration with [LiteLLM](https://github.com/BerriAI/litellm).\n\n\n## Features\n\n- [x] Event-driven & Scalable on-demand\n- [x] Monolithic or Distributed\n    - [x] Local Runtime (In-process Runtime)\n    - [x] HTTP Runtime (HTTP-based Distributed Runtime)\n    - [x] NATS Runtime (NATS-based Distributed Runtime)\n        - [ ] Using NATS [JetStream][1]\n- [x] Single-agent\n    - [x] [Function calling](https://platform.openai.com/docs/guides/function-calling)\n    - [x] [Structured Outputs][2] ([example](examples/structured-outputs))\n    - [ ] ReAct\n- [x] Multi-agent orchestration\n    - [x] Agent Discovery\n    - [x] Static orchestration\n        - [x] Sequential\n        - [x] Parallel\n    - [x] Dynamic orchestration\n        - [x] Dynamic Triage\n        - [x] Handoffs (based on async Swarm)\n- [x] Support any LLM\n- [x] Support [Model Context Protocol][3] ([example](examples/mcp))\n- [x] [CoS](coagent/cos) (Multi-language support)\n    - [x] [Python](examples/cos/cos.py)\n    - [x] [Node.js](examples/cos/cos.js)\n    - [x] [Go](examples/cos/goagent)\n    - [ ] Zig\n    - [ ] Rust\n\n\n## Three-tier Architecture\n\n<p align=\"center\">\n<img src=\"assets/coagent-three-tier-architecture.png\" height=\"500\">\n</p>\n\n\n## Installation\n\n```bash\npip install git+https://github.com/OpenCSGs/coagent.git\n```\n\n\n## Quick Start\n\n\n### Monolithic\n\nImplement the agent:\n\n```python\n# translator.py\n\nimport asyncio\nimport os\n\nfrom coagent.agents import ChatAgent, ChatMessage, ModelClient\nfrom coagent.core import AgentSpec, new, set_stderr_logger\nfrom coagent.runtimes import LocalRuntime\n\ntranslator = AgentSpec(\n    \"translator\",\n    new(\n        ChatAgent,\n        system=\"You are a professional translator that can translate Chinese to English.\",\n        client=ModelClient(model=\"openai/gpt-4o\", api_key=os.getenv(\"OPENAI_API_KEY\")),\n    ),\n)\n\n\nasync def main():\n    async with LocalRuntime() as runtime:\n        await runtime.register(translator)\n\n        result = await translator.run(\n            ChatMessage(role=\"user\", content=\"你好，世界\").encode(),\n            stream=True,\n        )\n        async for chunk in result:\n            msg = ChatMessage.decode(chunk)\n            print(msg.content, end=\"\", flush=True)\n\n\nif __name__ == \"__main__\":\n    set_stderr_logger()\n    asyncio.run(main())\n```\n\nRun the agent:\n\n```bash\nexport OPENAI_API_KEY=\"your-openai-key\"\npython translator.py\n```\n\n\n### Distributed\n\nStart a NATS server ([docs][4]):\n\n```bash\ndocker run -p 4222:4222 --name nats-server -ti nats:latest\n```\n\nImplement the agent:\n\n```python\n# translator.py\n\nimport asyncio\nimport os\n\nfrom coagent.agents import ChatAgent, ModelClient\nfrom coagent.core import AgentSpec, idle_loop, new, set_stderr_logger\nfrom coagent.runtimes import NATSRuntime\n\ntranslator = AgentSpec(\n    \"translator\",\n    new(\n        ChatAgent,\n        system=\"You are a professional translator that can translate Chinese to English.\",\n        client=ModelClient(model=\"openai/gpt-4o\", api_key=os.getenv(\"OPENAI_API_KEY\")),\n    ),\n)\n\n\nasync def main():\n    async with NATSRuntime.from_servers(\"nats://localhost:4222\") as runtime:\n        await runtime.register(translator)\n        await idle_loop()\n\n\nif __name__ == \"__main__\":\n    set_stderr_logger()\n    asyncio.run(main())\n```\n\nRun the agent as a daemon:\n\n```bash\nexport OPENAI_API_KEY=\"your-openai-key\"\npython translator.py\n```\n\nCommunicate with the agent using the `coagent` CLI:\n\n```bash\ncoagent translator -H type:ChatMessage --chat -d '{\"role\": \"user\", \"content\": \"你好，世界\"}'\n```\n\n\n## Patterns\n\n(The following patterns are mainly inspired by [Anthropic's Building effective agents][5] and [OpenAI's Handoffs][6].)\n\n### Basic: Augmented LLM\n\n**Augmented LLM** is an LLM enhanced with augmentations such as retrieval, tools, and memory. Our current models can actively use these capabilities—generating their own search queries, selecting appropriate tools, and determining what information to retain.\n\n<p align=\"center\">\n<img src=\"assets/patterns-augmented-llm.png\">\n</p>\n\n**Example** (see [examples/patterns/augmented_llm.py](examples/patterns/augmented_llm.py) for a runnable example):\n\n```python\nfrom coagent.agents import ChatAgent, ModelClient, tool\nfrom coagent.core import AgentSpec, new\n\n\nclass Assistant(ChatAgent):\n    system = \"\"\"You are an agent who can use tools.\"\"\"\n    client = ModelClient(...)\n\n    @tool\n    async def query_weather(self, city: str) -> str:\n        \"\"\"Query the weather in the given city.\"\"\"\n        return f\"The weather in {city} is sunny.\"\n\n\nassistant = AgentSpec(\"assistant\", new(Assistant))\n```\n\n### Workflow: Chaining\n\n**Chaining** decomposes a task into a sequence of steps, where each agent processes the output of the previous one.\n\n<p align=\"center\">\n<img src=\"assets/patterns-chaining.png\">\n</p>\n\n**When to use this workflow:** This workflow is ideal for situations where the task can be easily and cleanly decomposed into fixed subtasks. The main goal is to trade off latency for higher accuracy, by making each agent an easier task.\n\n**Example** (see [examples/patterns/chaining.py](examples/patterns/chaining.py) for a runnable example):\n\n```python\nfrom coagent.agents import ChatAgent, Sequential, ModelClient\nfrom coagent.core import AgentSpec, new\n\nclient = ModelClient(...)\n\nextractor = AgentSpec(\n    \"extractor\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nExtract only the numerical values and their associated metrics from the text.\nFormat each as 'value: metric' on a new line.\nExample format:\n92: customer satisfaction\n45%: revenue growth\\\n\"\"\",\n        client=client,\n    ),\n)\n\nconverter = AgentSpec(\n    \"converter\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nConvert all numerical values to percentages where possible.\nIf not a percentage or points, convert to decimal (e.g., 92 points -> 92%).\nKeep one number per line.\nExample format:\n92%: customer satisfaction\n45%: revenue growth\\\n\"\"\",\n        client=client,\n    ),\n)\n\nsorter = AgentSpec(\n    \"sorter\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nSort all lines in descending order by numerical value.\nKeep the format 'value: metric' on each line.\nExample:\n92%: customer satisfaction\n87%: employee satisfaction\\\n\"\"\",\n        client=client,\n    ),\n)\n\nformatter = AgentSpec(\n    \"formatter\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nFormat the sorted data as a markdown table with columns:\n| Metric | Value |\n|:--|--:|\n| Customer Satisfaction | 92% |\\\n\"\"\",\n        client=client,\n    ),\n)\n\nchain = AgentSpec(\n    \"chain\", new(Sequential, \"extractor\", \"converter\", \"sorter\", \"formatter\")\n)\n```\n\n### Workflow: Parallelization\n\n**Parallelization** distributes independent subtasks across multiple agents for concurrent processing.\n\n<p align=\"center\">\n<img src=\"assets/patterns-parallelization.png\">\n</p>\n\n**When to use this workflow:** Parallelization is effective when the divided subtasks can be parallelized for speed, or when multiple perspectives or attempts are needed for higher confidence results.\n\n**Example** (see [examples/patterns/parallelization.py](examples/patterns/parallelization.py) for a runnable example):\n\n```python\nfrom coagent.agents import Aggregator, ChatAgent, ModelClient, Parallel\nfrom coagent.core import AgentSpec, new\n\nclient = ModelClient(...)\n\ncustomer = AgentSpec(\n    \"customer\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nCustomers:\n- Price sensitive\n- Want better tech\n- Environmental concerns\\\n\"\"\",\n        client=client,\n    ),\n)\n\nemployee = AgentSpec(\n    \"employee\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nEmployees:\n- Job security worries\n- Need new skills\n- Want clear direction\\\n\"\"\",\n        client=client,\n    ),\n)\n\ninvestor = AgentSpec(\n    \"investor\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nInvestors:\n- Expect growth\n- Want cost control\n- Risk concerns\\\n\"\"\",\n        client=client,\n    ),\n)\n\nsupplier = AgentSpec(\n    \"supplier\",\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nSuppliers:\n- Capacity constraints\n- Price pressures\n- Tech transitions\\\n\"\"\",\n        client=client,\n    ),\n)\n\naggregator = AgentSpec(\"aggregator\", new(Aggregator))\n\nparallel = AgentSpec(\n    \"parallel\",\n    new(\n        Parallel,\n        \"customer\",\n        \"employee\",\n        \"investor\",\n        \"supplier\",\n        aggregator=\"aggregator\",\n    ),\n)\n```\n\n\n### Workflow: Triaging & Routing\n\n**Triaging** classifies an input and directs it to a specialized followup agent. This workflow allows for separation of concerns, and building more specialized agents.\n\n<p align=\"center\">\n<img src=\"assets/patterns-triaging.png\">\n</p>\n\n**When to use this workflow:** This workflow works well for complex tasks where there are distinct categories that are better handled separately, and where classification can be handled accurately, either by an LLM (using Prompting or Function-calling) or a more traditional classification model/algorithm.\n\n**Example** (see [examples/patterns/triaging.py](examples/patterns/triaging.py) for a runnable example):\n\n```python\nfrom coagent.agents import ChatAgent, DynamicTriage, ModelClient\nfrom coagent.core import AgentSpec, new\n\nclient = ModelClient(...)\n\nbilling = AgentSpec(\n    \"team.billing\",  # Under the team namespace\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nYou are a billing support specialist. Follow these guidelines:\n1. Always start with \"Billing Support Response:\"\n2. First acknowledge the specific billing issue\n3. Explain any charges or discrepancies clearly\n4. List concrete next steps with timeline\n5. End with payment options if relevant\n\nKeep responses professional but friendly.\\\n\"\"\",\n        client=client,\n    ),\n)\n\naccount = AgentSpec(\n    \"team.account\",  # Under the team namespace\n    new(\n        ChatAgent,\n        system=\"\"\"\\\nYou are an account security specialist. Follow these guidelines:\n1. Always start with \"Account Support Response:\"\n2. Prioritize account security and verification\n3. Provide clear steps for account recovery/changes\n4. Include security tips and warnings\n5. Set clear expectations for resolution time\n\nMaintain a serious, security-focused tone.\\\n\"\"\",\n        client=client,\n    ),\n)\n\ntriage = AgentSpec(\n    \"triage\",\n    new(\n        DynamicTriage,\n        system=\"\"\"You are a triage agent who will delegate to sub-agents based on the conversation content.\"\"\",\n        client=client,\n        namespace=\"team\",  # Collect all sub-agents under the team namespace\n    ),\n)\n```\n\n\n## Examples\n\n- [patterns](examples/patterns)\n- [mcp](examples/mcp)\n- [structured-outputs](examples/structured-outputs)\n- [deepseek-r1](examples/deepseek-r1)\n- [ping-pong](examples/ping-pong)\n- [stream-ping-pong](examples/stream-ping-pong)\n- [discovery](examples/discovery)\n- [translator](examples/translator)\n- [notification](examples/notification)\n- [opencsg](examples/opencsg)\n- [app-builder](examples/app-builder)\n- [autogen](examples/autogen)\n- [cos](examples/cos)\n\n\n[1]: https://docs.nats.io/nats-concepts/jetstream\n[2]: https://platform.openai.com/docs/guides/structured-outputs\n[3]: https://modelcontextprotocol.io/introduction\n[4]: https://docs.nats.io/running-a-nats-service/nats_docker/nats-docker-tutorial\n[5]: https://www.anthropic.com/research/building-effective-agents\n[6]: https://cookbook.openai.com/examples/orchestrating_agents\n"}