[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-langroid--langroid":3,"tool-langroid--langroid":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":70,"readme_en":71,"readme_zh":72,"quickstart_zh":73,"use_case_zh":74,"hero_image_url":75,"owner_login":67,"owner_name":76,"owner_avatar_url":77,"owner_bio":68,"owner_company":78,"owner_location":78,"owner_email":78,"owner_twitter":78,"owner_website":78,"owner_url":79,"languages":80,"stars":96,"forks":97,"last_commit_at":98,"license":99,"difficulty_score":100,"env_os":101,"env_gpu":102,"env_ram":103,"env_deps":104,"category_tags":114,"github_topics":115,"view_count":23,"oss_zip_url":78,"oss_zip_packed_at":78,"status":16,"created_at":134,"updated_at":135,"faqs":136,"releases":166},2778,"langroid\u002Flangroid","langroid","Harness LLMs with Multi-Agent Programming","Langroid 是一个由卡内基梅隆大学和威斯康星大学麦迪逊分校研究人员打造的 Python 框架，旨在帮助开发者轻松构建基于大语言模型（LLM）的多智能体应用。它通过模拟“演员模型”，让用户定义多个具备不同能力的智能体（如配备 LLM、向量数据库或工具函数），这些智能体通过相互发送消息协作，共同解决复杂任务。\n\n传统的大模型应用开发往往依赖复杂的编排逻辑或重型框架，而 Langroid 提供了一种更直观、轻量且原则清晰的替代方案。它不依赖 LangChain 等其他中间层，直接支持市面上绝大多数大模型，显著降低了开发门槛，让开发者能专注于业务逻辑而非底层架构。此外，Langroid 还率先支持 MCP 协议，允许智能体灵活调用外部服务器工具，并提供了可选的 Claude Code 插件以加速开发流程。\n\n这款工具特别适合希望深入探索多智能体协作模式的 AI 开发者、研究人员以及需要构建生产级安全应用的企业团队。已有如 Nullify 等公司在评估了多种主流框架后，选择将 Langroid 应用于实际生产中，用于自动化漏洞修复等关键场景。如果你正在寻找一个既简洁又强大的框架来释放多智能","Langroid 是一个由卡内基梅隆大学和威斯康星大学麦迪逊分校研究人员打造的 Python 框架，旨在帮助开发者轻松构建基于大语言模型（LLM）的多智能体应用。它通过模拟“演员模型”，让用户定义多个具备不同能力的智能体（如配备 LLM、向量数据库或工具函数），这些智能体通过相互发送消息协作，共同解决复杂任务。\n\n传统的大模型应用开发往往依赖复杂的编排逻辑或重型框架，而 Langroid 提供了一种更直观、轻量且原则清晰的替代方案。它不依赖 LangChain 等其他中间层，直接支持市面上绝大多数大模型，显著降低了开发门槛，让开发者能专注于业务逻辑而非底层架构。此外，Langroid 还率先支持 MCP 协议，允许智能体灵活调用外部服务器工具，并提供了可选的 Claude Code 插件以加速开发流程。\n\n这款工具特别适合希望深入探索多智能体协作模式的 AI 开发者、研究人员以及需要构建生产级安全应用的企业团队。已有如 Nullify 等公司在评估了多种主流框架后，选择将 Langroid 应用于实际生产中，用于自动化漏洞修复等关键场景。如果你正在寻找一个既简洁又强大的框架来释放多智能体系统的潜力，Langroid 值得尝试。","\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flangroid_langroid_readme_cfee98aa6601.png\" alt=\"Logo\"\n        width=\"400\" align=\"center\">\n\u003C\u002Fdiv>\n\n\u003Cdiv align=\"center\">\n\n[![PyPI - Version](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Flangroid)](https:\u002F\u002Fpypi.org\u002Fproject\u002Flangroid\u002F)\n[![Downloads](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fdm\u002Flangroid)](https:\u002F\u002Fpypi.org\u002Fproject\u002Flangroid\u002F)\n[![Pytest](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fpytest.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fpytest.yml)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Flangroid\u002Flangroid\u002Fgraph\u002Fbadge.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Flangroid\u002Flangroid)\n[![Multi-Architecture DockerHub](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fdocker-publish.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fdocker-publish.yml)\n\n[![Static Badge](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDocumentation-blue?link=https%3A%2F%2Flangroid.github.io%2Flangroid%2F&link=https%3A%2F%2Flangroid.github.io%2Flangroid%2F)](https:\u002F\u002Flangroid.github.io\u002Flangroid)\n[![Open in Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb)\n[![Discord](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDiscord-%235865F2.svg?style=flat&logo=discord&logoColor=white)](https:\u002F\u002Fdiscord.gg\u002FZU36McDgDs)\n[![Substack](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSubstack-%23006f5c.svg?style=flat&logo=substack&logoColor=FF6719)](https:\u002F\u002Flangroid.substack.com\u002Fp\u002Flangroid-harness-llms-with-multi-agent-programming)\n\n\u003C\u002Fdiv>\n\n\u003Ch3 align=\"center\">\n  \u003Ca target=\"_blank\" \n    href=\"https:\u002F\u002Flangroid.github.io\u002Flangroid\u002F\" rel=\"dofollow\">\n      \u003Cstrong>Documentation\u003C\u002Fstrong>\u003C\u002Fa>\n  &middot;\n  \u003Ca target=\"_blank\" href=\"https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\" rel=\"dofollow\">\n      \u003Cstrong>Examples Repo\u003C\u002Fstrong>\u003C\u002Fa>\n  &middot;\n  \u003Ca target=\"_blank\" href=\"https:\u002F\u002Fdiscord.gg\u002FZU36McDgDs\" rel=\"dofollow\">\n      \u003Cstrong>Discord\u003C\u002Fstrong>\u003C\u002Fa>\n  &middot;\n  \u003Ca target=\"_blank\" href=\"https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002FCONTRIBUTING.md\" rel=\"dofollow\">\n      \u003Cstrong>Contributing\u003C\u002Fstrong>\u003C\u002Fa>\n\n  \u003Cbr \u002F>\n\u003C\u002Fh3>\n\n`Langroid` is an intuitive, lightweight, extensible and principled\nPython framework to easily build LLM-powered applications, from CMU and UW-Madison researchers. \nYou set up Agents, equip them with optional components (LLM, \nvector-store and tools\u002Ffunctions), assign them tasks, and have them \ncollaboratively solve a problem by exchanging messages. \nThis Multi-Agent paradigm is inspired by the\n[Actor Framework](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FActor_model)\n(but you do not need to know anything about this!). \n\n`Langroid` is a fresh take on LLM app-development, where considerable thought has gone \ninto simplifying the developer experience; \nit does not use `Langchain`, or any other LLM framework, \nand works with [practically any LLM](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fsupported-models\u002F).\n\n🔥 ✨ A Claude Code [plugin](#claude-code-plugin-optional) is available to\naccelerate Langroid development with built-in patterns and best practices.\n\n\n🔥 Read the (WIP) [overview of the langroid architecture](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fblog\u002F2024\u002F08\u002F15\u002Foverview-of-langroids-multi-agent-architecture-prelim\u002F), \n and a [quick tour of Langroid](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flangroid-tour\u002F).\n\n🔥 MCP Support: Allow any LLM-Agent to leverage MCP Servers via Langroid's simple\n[MCP tool adapter](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fmcp-tools\u002F) that converts \nthe server's tools into Langroid's `ToolMessage` instances.\n\n📢 Companies are using\u002Fadapting Langroid in **production**. Here is a quote:\n\n>[Nullify](https:\u002F\u002Fwww.nullify.ai) uses AI Agents for secure software development. \n> It finds, prioritizes and fixes vulnerabilities. We have internally adapted Langroid's multi-agent orchestration framework in production, after evaluating CrewAI, Autogen, LangChain, Langflow, etc. We found Langroid to be far superior to those frameworks in terms of ease of setup and flexibility. Langroid's Agent and Task abstractions are intuitive, well thought out, and provide a great developer  experience. We wanted the quickest way to get something in production. With other frameworks it would have taken us weeks, but with Langroid we got to good results in minutes. Highly recommended! \u003Cbr> -- Jacky Wong, Head of AI at Nullify.\n\n\n🔥 See this [Intro to Langroid](https:\u002F\u002Flancedb.substack.com\u002Fp\u002Flangoid-multi-agent-programming-framework)\nblog post from the LanceDB team\n\n🔥 Just published in ML for Healthcare (2024): a Langroid-based Multi-Agent RAG system for \npharmacovigilance, see [blog post](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fblog\u002F2024\u002F08\u002F12\u002Fmalade-multi-agent-architecture-for-pharmacovigilance\u002F)\n\n\nWe welcome contributions: See the [contributions](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002FCONTRIBUTING.md) document\nfor ideas on what to contribute.\n\nAre you building LLM Applications, or want help with Langroid for your company, \nor want to prioritize Langroid features for your company use-cases? \n[Prasad Chalasani](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fpchalasani\u002F) is available for consulting\n(advisory\u002Fdevelopment): pchalasani at gmail dot com.\n\nSponsorship is also accepted via [GitHub Sponsors](https:\u002F\u002Fgithub.com\u002Fsponsors\u002Flangroid)\n\n**Questions, Feedback, Ideas? Join us on [Discord](https:\u002F\u002Fdiscord.gg\u002FZU36McDgDs)!**\n\n# Quick glimpse of coding with Langroid\nThis is just a teaser; there's much more, like function-calling\u002Ftools, \nMulti-Agent Collaboration, Structured Information Extraction, DocChatAgent \n(RAG), SQLChatAgent, non-OpenAI local\u002Fremote LLMs, etc. Scroll down or see docs for more.\nSee the Langroid Quick-Start [Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb)\nthat builds up to a 2-agent information-extraction example using the OpenAI ChatCompletion API. \nSee also this [version](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F190Tk7t4AdY1P9F_NlZ33-YEoGnHweQQ0) that uses the OpenAI Assistants API instead.\n\n🔥 just released! [Example](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat-multi-extract-local.py) \nscript showing how you can use Langroid multi-agents and tools\nto extract structured information from a document using **only a local LLM**\n(Mistral-7b-instruct-v0.2).\n\n```python\nimport langroid as lr\nimport langroid.language_models as lm\n\n# set up LLM\nllm_cfg = lm.OpenAIGPTConfig( # or OpenAIAssistant to use Assistant API \n  # any model served via an OpenAI-compatible API\n  chat_model=lm.OpenAIChatModel.GPT4o, # or, e.g., \"ollama\u002Fmistral\"\n)\n# use LLM directly\nmdl = lm.OpenAIGPT(llm_cfg)\nresponse = mdl.chat(\"What is the capital of Ontario?\", max_tokens=10)\n\n# use LLM in an Agent\nagent_cfg = lr.ChatAgentConfig(llm=llm_cfg)\nagent = lr.ChatAgent(agent_cfg)\nagent.llm_response(\"What is the capital of China?\") \nresponse = agent.llm_response(\"And India?\") # maintains conversation state \n\n# wrap Agent in a Task to run interactive loop with user (or other agents)\ntask = lr.Task(agent, name=\"Bot\", system_message=\"You are a helpful assistant\")\ntask.run(\"Hello\") # kick off with user saying \"Hello\"\n\n# 2-Agent chat loop: Teacher Agent asks questions to Student Agent\nteacher_agent = lr.ChatAgent(agent_cfg)\nteacher_task = lr.Task(\n  teacher_agent, name=\"Teacher\",\n  system_message=\"\"\"\n    Ask your student concise numbers questions, and give feedback. \n    Start with a question.\n    \"\"\"\n)\nstudent_agent = lr.ChatAgent(agent_cfg)\nstudent_task = lr.Task(\n  student_agent, name=\"Student\",\n  system_message=\"Concisely answer the teacher's questions.\",\n  single_round=True,\n)\n\nteacher_task.add_sub_task(student_task)\nteacher_task.run()\n```\n\n# 🔥 Updates\u002FReleases\n\n\u003Cdetails>\n\u003Csummary> \u003Cb>Click to expand\u003C\u002Fb>\u003C\u002Fsummary>\n\n- **Aug 2025:**\n  - [0.59.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.59.0) Complete Pydantic V2 Migration - \n    5-50x faster validation, modern Python patterns, 100% backward compatible.\n- **Jul 2025:**\n  - [0.58.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.58.0) Crawl4AI integration - \n    browser-based web crawling with Playwright for JavaScript-heavy sites, no API key required (thank you @abab-dev!).\n  - [0.57.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.57.0) HTML Logger for interactive task visualization - \n    self-contained HTML logs with collapsible entries, auto-refresh, and persistent UI state.\n- **Jun 2025:**\n  - [0.56.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.56.0) `TaskTool` for delegating tasks to sub-agents - \n    enables agents to spawn sub-agents with specific tools and configurations.\n  - [0.55.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.55.0) Event-based task termination with `done_sequences` - \n    declarative task completion using event patterns.\n  - [0.54.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.54.0) Portkey AI Gateway support - access 200+ models \n    across providers through unified API with caching, retries, observability.\n- **Mar-Apr 2025:**\n  - [0.53.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.53.0) MCP Tools Support.\n  - [0.52.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.52.0) Multimodal support, i.e. allow PDF, image \n    inputs to LLM.\n  - [0.51.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.51.0) `LLMPdfParser`, generalizing \n    `GeminiPdfParser` to parse documents directly with LLM.\n  - [0.50.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.50.0) Structure-aware Markdown chunking with chunks \n    enriched by section headers.\n  - [0.49.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.49.0) Enable easy switch to LiteLLM Proxy-server \n  - [0.48.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.48.0) Exa Crawler, Markitdown Parser\n  - [0.47.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.47.0) Support Firecrawl URL scraper\u002Fcrawler - \n    thanks @abab-dev\n  - [0.46.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.46.0) Support LangDB LLM Gateway - thanks @MrunmayS.\n  - [0.45.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.45.0) Markdown parsing with `Marker` - thanks @abab-dev\n  - [0.44.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.44.0) Late imports to reduce startup time. Thanks \n    @abab-dev\n- **Feb 2025:**\n  - [0.43.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.43.0): `GeminiPdfParser` for parsing PDF using \n    Gemini LLMs - Thanks @abab-dev.\n  - [0.42.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.42.0): `markitdown` parser for `pptx,xlsx,xls` files \n    Thanks @abab-dev.\n  - [0.41.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.41.0): `pinecone` vector-db (Thanks @coretado), \n    `Tavily` web-search (Thanks @Sozhan308), `Exa` web-search (Thanks @MuddyHope).\n  - [0.40.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.40.0): `pgvector` vector-db. Thanks @abab-dev.\n  - [0.39.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.39.0): `ChatAgentConfig.handle_llm_no_tool` for \n    handling LLM \"forgetting\" to use a tool.\n  - [0.38.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.38.0): Gemini embeddings - Thanks @abab-dev)\n  - [0.37.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.37.0): New PDF Parsers: `docling`, `pymupdf4llm`\n- **Jan 2025:**\n  - [0.36.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.36.0): Weaviate vector-db support (thanks @abab-dev).\n  - [0.35.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.35.0): Capture\u002FStream reasoning content from \n    Reasoning LLMs (e.g. DeepSeek-R1, OpenAI o1) in addition to final answer.\n  - [0.34.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.34.0): DocChatAgent \n    chunk enrichment to improve retrieval. (collaboration with @dfm88). \n  - [0.33.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.33.3) Move from Poetry to uv! (thanks @abab-dev).\n  - [0.32.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.32.0) DeepSeek v3 support.\n- **Dec 2024:**\n  - [0.31.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.31.0) Azure OpenAI Embeddings\n  - [0.30.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.30.0) Llama-cpp embeddings (thanks @Kwigg).\n  - [0.29.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.29.0) Custom Azure OpenAI Client (thanks \n    @johannestang).\n  - [0.28.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.28.0) `ToolMessage`: `_handler` field to override \ndefault handler method name in `request` field (thanks @alexagr).\n  - [0.27.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.27.0) OpenRouter Support.\n  - [0.26.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.26.0) Update to latest Chainlit.\n  - [0.25.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.25.0) True Async Methods for agent and \n    user-response (thanks @alexagr).\n- **Nov 2024:**\n  - **[0.24.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fstructured-output\u002F)**: \n     Enables support for `Agent`s with strict JSON schema output format on compatible LLMs and strict mode for the OpenAI tools API.\n    (thanks @nilspalumbo).\n  - **[0.23.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F#local-llms-hosted-on-glhfchat)**: \n      support for LLMs (e.g. `Qwen2.5-Coder-32b-Instruct`) hosted on glhf.chat \n  - **[0.22.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Flarge-tool-results\u002F)**: \n     Optional parameters to truncate large tool results.\n  - **[0.21.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fgemini\u002F)** Direct support for Gemini models via OpenAI client instead of using LiteLLM.\n  - **[0.20.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.20.0)** Support for \n    ArangoDB Knowledge Graphs.\n- **Oct 2024:**\n  - **[0.18.0]** [LLMConfig.async_stream_quiet](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fasync-streaming\u002F) flag to \n    turn off LLM output in async + stream mode.\n  - **[0.17.0]** XML-based tools, see [docs](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fxml-tools\u002F).\n- **Sep 2024:**\n  - **[0.16.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.16.0)**  Support for OpenAI `o1-mini` and `o1-preview` models.\n  - **[0.15.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.15.0)** Cerebras API support -- run llama-3.1 models hosted on Cerebras Cloud (very fast inference).\n  - **[0.14.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.14.0)** `DocChatAgent` uses Reciprocal Rank Fusion (RRF) to rank chunks retrieved by different methods.\n  - **[0.12.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.12.0)** `run_batch_task` new option -- `stop_on_first_result` - allows termination of batch as soon as any task returns a result.  \n- **Aug 2024:**\n  - **[0.11.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.11.0)** Polymorphic `Task.run(), Task.run_async`.\n  - **[0.10.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.10.0)** Allow tool handlers to return arbitrary result type, including other tools.\n  - **[0.9.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.9.0)** Orchestration Tools, to signal various task statuses, and to pass messages between agents.\n  - **[0.7.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.7.0)** OpenAI tools API support, including multi-tools.\n- **Jul 2024:**\n  - **[0.3.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.3.0)**: Added [FastEmbed](https:\u002F\u002Fqdrant.github.io\u002Ffastembed\u002Fqdrant\u002FUsage_With_Qdrant\u002F) embeddings from Qdrant\n- **Jun 2024:**\n  - **0.2.0:** Improved lineage tracking, granular sub-task configs, and a new tool, `RewindTool`, \n    that lets an agent \"rewind and redo\" a past message (and all dependent messages are cleared out \n    thanks to the lineage tracking). Read notes [here](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.2.0).\n- **May 2024:** \n  - **Slimmer langroid**: All document-parsers (i.e. pdf, doc, docx) and most \n    vector-databases (except qdrant) \n    are now optional\u002Fextra dependencies, which helps reduce build size, script \n    start-up time, and install time. For convenience various grouping of \"extras\" are \n    provided, e.g. `doc-chat`, `db` (for database-related dependencies). See updated \n    install instructions below and in the docs.\n  - **Few-shot examples** for tools: when defining a [ToolMessage](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002Fchat-agent-tool\u002F#example-find-the-smallest-number-in-a-list), previously you were able to include a classmethod named `examples`,\n    and a random example from this list would be used to generate a 1-shot example \n    for the LLM. This has been improved so you can now supply a list of examples \n    where each example is either a tool instance, or a tuple of (description, \n    tool instance), where the description is a \"thought\" that leads the LLM to use \n    the tool (see example in the [docs](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002Fchat-agent-tool\u002F#example-find-the-smallest-number-in-a-list)). In some scenarios this can improve LLM tool \n    generation accuracy. Also, now instead of a random example, ALL examples are used to generate few-shot \n    examples.     \n  - [Infinite loop detection](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002F0ed30eb467b00d5eaf2933b577a4b2cc37de1aa1\u002Flangroid\u002Fagent\u002Ftask.py#L1121) for task loops of cycle-length \u003C= 10 (configurable \n    in [`TaskConfig`](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Freference\u002Fagent\u002Ftask\u002F#langroid.agent.task.TaskConfig). Only detects _exact_ loops, rather than _approximate_ loops where the entities are saying essentially similar (but not exactly the same) things repeatedly.\n  - \"@\"-addressing: any entity can address any other by name, which can be the name \n    of an agent's responder (\"llm\", \"user\", \"agent\") or a sub-task name. This is a \n    simpler alternative to the `RecipientTool` mechanism, with the tradeoff that \n    since it's not a tool, there's no way to enforce\u002Fremind the LLM to explicitly \n    specify an addressee (in scenarios where this is important).\n  - [Much-Improved Citation](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fissues\u002F477) \n    generation and display when using `DocChatAgent`.\n  - `gpt-4o` is now the default LLM throughout; Update tests and examples to work \n    with this LLM; use tokenizer corresponding to the LLM.\n  - `gemini 1.5 pro` support via `litellm`\n  - `QdrantDB:` update to support learned sparse embeddings.\n- **Apr 2024:**\n  - **0.1.236**: Support for open LLMs hosted on Groq, e.g. specify \n    `chat_model=\"groq\u002Fllama3-8b-8192\"`.\n      See [tutorial](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F).\n  - **0.1.235**: `Task.run(), Task.run_async(), run_batch_tasks` have `max_cost` \n    and `max_tokens` params to exit when tokens or cost exceed a limit. The result \n    `ChatDocument.metadata` now includes a `status` field which is a code indicating a \n     task completion reason code. Also `task.run()` etc can be invoked with an explicit\n     `session_id` field which is used as a key to look up various settings in Redis cache.\n    Currently only used to look up \"kill status\" - this allows killing a running task, either by `task.kill()`\n    or by the classmethod `Task.kill_session(session_id)`.\n    For example usage, see the `test_task_kill` in [tests\u002Fmain\u002Ftest_task.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_task.py)\n  \n- **Mar 2024:**\n  - **0.1.216:** Improvements to allow concurrent runs of `DocChatAgent`, see the\n    [`test_doc_chat_agent.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_doc_chat_agent.py)\n    in particular the `test_doc_chat_batch()`;\n    New task run utility: [`run_batch_task_gen`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fbatch.py) \n    where a task generator can be specified, to generate one task per input. \n  - **0.1.212:** ImagePdfParser: support for extracting text from image-based PDFs.\n    (this means `DocChatAgent` will now work with image-pdfs).\n  - **0.1.194 - 0.1.211:** Misc fixes, improvements, and features:\n    - Big enhancement in RAG performance (mainly, recall) due to a [fix in Relevance \n      Extractor](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.209)\n    - `DocChatAgent` [context-window fixes](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.208)\n    - Anthropic\u002FClaude3 support via Litellm\n    - `URLLoader`: detect file time from header when URL doesn't end with a \n      recognizable suffix like `.pdf`, `.docx`, etc.\n    - Misc lancedb integration fixes\n    - Auto-select embedding config based on whether `sentence_transformer` module is available.\n    - Slim down dependencies, make some heavy ones optional, e.g. `unstructured`, \n      `haystack`, `chromadb`, `mkdocs`, `huggingface-hub`, `sentence-transformers`.\n    - Easier top-level imports from `import langroid as lr`\n    - Improve JSON detection, esp from weak LLMs\n- **Feb 2024:** \n  - **0.1.193:** Support local LLMs using Ollama's new OpenAI-Compatible server: \n     simply specify `chat_model=\"ollama\u002Fmistral\"`. See [release notes](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.193).\n  - **0.1.183:** Added Chainlit support via [callbacks](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fcallbacks\u002Fchainlit.py). \n   See [examples](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Ftree\u002Fmain\u002Fexamples\u002Fchainlit).\n- **Jan 2024:**\n  - **0.1.175** \n    - [Neo4jChatAgent](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Ftree\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fneo4j) to chat with a neo4j knowledge-graph.\n      (Thanks to [Mohannad](https:\u002F\u002Fgithub.com\u002FMohannadcse)!). The agent uses tools to query the Neo4j schema and translate user queries to Cypher queries,\n      and the tool handler executes these queries, returning them to the LLM to compose\n      a natural language response (analogous to how `SQLChatAgent` works).\n      See example [script](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Ftree\u002Fmain\u002Fexamples\u002Fkg-chat) using this Agent to answer questions about Python pkg dependencies.\n    - Support for `.doc` file parsing (in addition to `.docx`)\n    - Specify optional [`formatter` param](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.171) \n      in `OpenAIGPTConfig` to ensure accurate chat formatting for local LLMs. \n  - **[0.1.157](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.157):** `DocChatAgentConfig` \n     has a new param: `add_fields_to_content`, to specify additional document fields to insert into \n     the main `content` field, to help improve retrieval.\n  - **[0.1.156](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.156):** New Task control signals\n     PASS_TO, SEND_TO; VectorStore: Compute Pandas expression on documents; LanceRAGTaskCreator creates 3-agent RAG system with Query Planner, Critic and RAG Agent.\n- **Dec 2023:**\n  - **0.1.154:** (For details see release notes of [0.1.149](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.149)\n      and [0.1.154](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.154)). \n    - `DocChatAgent`: Ingest Pandas dataframes and filtering.\n    - `LanceDocChatAgent` leverages `LanceDB` vector-db for efficient vector search\n     and full-text search and filtering.\n    - Improved task and multi-agent control mechanisms\n    - `LanceRAGTaskCreator` to create a 2-agent system consisting of a `LanceFilterAgent` that\n      decides a filter and rephrase query to send to a RAG agent.\n  - **[0.1.141](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.141):**\n    API Simplifications to reduce boilerplate:\n    auto-select an available OpenAI model (preferring gpt-4o), simplifies defaults.\n    Simpler `Task` initialization with default `ChatAgent`.\n- **Nov 2023:**\n  - **[0.1.126](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.126):**\n     OpenAIAssistant agent: Caching Support. \n  - **0.1.117:** Support for OpenAI Assistant API tools: Function-calling, \n    Code-intepreter, and Retriever (RAG), file uploads. These work seamlessly \n    with Langroid's task-orchestration.\n    Until docs are ready, it's best to see these usage examples:\n    \n    - **Tests:**\n      - [test_openai_assistant.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant.py)\n      - [test_openai_assistant_async.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant_async.py)\n\n    - **Example scripts:**\n      - [The most basic chat app](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Foai-asst-chat.py)\n      - [Chat with code interpreter](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Foai-code-chat.py)\n      - [Chat with retrieval (RAG)](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Foai-retrieval-assistant.py)\n      - [2-agent RAG chat](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Foai-retrieval-2.py)\n  - **0.1.112:** [`OpenAIAssistant`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fopenai_assistant.py) is a subclass of `ChatAgent` that \n    leverages the new OpenAI Assistant API. It can be used as a drop-in \n    replacement for `ChatAgent`, and relies on the Assistant API to\n    maintain conversation state, and leverages persistent threads and \n    assistants to reconnect to them if needed. Examples: \n    [`test_openai_assistant.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant.py),\n    [`test_openai_assistant_async.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant_async.py)\n  - **0.1.111:** Support latest OpenAI model: `GPT4_TURBO`\n(see [test_llm.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_llm.py) for example usage)\n  - **0.1.110:** Upgrade from OpenAI v0.x to v1.1.1 (in preparation for \n    Assistants API and more); (`litellm` temporarily disabled due to OpenAI \n    version conflict).\n- **Oct 2023:**\n  - **0.1.107:** `DocChatAgent` re-rankers: `rank_with_diversity`, `rank_to_periphery` (lost in middle).\n  - **0.1.102:** `DocChatAgentConfig.n_neighbor_chunks > 0` allows returning context chunks around match.\n  - **0.1.101:** `DocChatAgent` uses `RelevanceExtractorAgent` to have \n    the LLM extract relevant portions of a chunk using \n    sentence-numbering, resulting in huge speed up and cost reduction \n    compared to the naive \"sentence-parroting\" approach (writing out full \n    sentences out relevant whole sentences) which `LangChain` uses in their \n    `LLMChainExtractor`.\n  - **0.1.100:** API update: all of Langroid is accessible with a single import, i.e. `import langroid as lr`. See the [documentation](\"https:\u002F\u002Flangroid.github.io\u002Flangroid\u002F\") for usage.\n  - **0.1.99:** Convenience batch functions to run tasks, agent methods on a list of inputs concurrently in async mode. See examples in [test_batch.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_batch.py).\n  - **0.1.95:** Added support for [Momento Serverless Vector Index](https:\u002F\u002Fdocs.momentohq.com\u002Fvector-index)\n  - **0.1.94:** Added support for [LanceDB](https:\u002F\u002Flancedb.github.io\u002Flancedb\u002F) vector-store -- allows vector, Full-text, SQL search.\n  - **0.1.84:** Added [LiteLLM](https:\u002F\u002Fdocs.litellm.ai\u002Fdocs\u002Fproviders), so now Langroid can be used with over 100 LLM providers (remote or local)! \n     See guide [here](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F).\n- **Sep 2023:**\n  - **0.1.78:** Async versions of several Task, Agent and LLM methods; \n      Nested Pydantic classes are now supported for LLM Function-calling, Tools, Structured Output.    \n  - **0.1.76:** DocChatAgent: support for loading `docx` files (preliminary).\n  - **0.1.72:** Many improvements to DocChatAgent: better embedding model, \n          hybrid search to improve retrieval, better pdf parsing, re-ranking retrieved results with cross-encoders. \n  - **Use with local LLama Models:** see tutorial [here](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fblog\u002F2023\u002F09\u002F14\u002Fusing-langroid-with-local-llms\u002F)\n  - **Langroid Blog\u002FNewsletter Launched!**: First post is [here](https:\u002F\u002Fsubstack.com\u002Fnotes\u002Fpost\u002Fp-136704592) -- Please subscribe to stay updated. \n  - **0.1.56:** Support Azure OpenAI. \n  - **0.1.55:** Improved [`SQLChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fsql\u002Fsql_chat_agent.py) that efficiently retrieves relevant schema info when translating natural language to SQL.  \n- **Aug 2023:**\n  - **[Hierarchical computation](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fexamples\u002Fagent-tree\u002F)** example using Langroid agents and task orchestration.\n  - **0.1.51:** Support for global state, see [test_global_state.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_global_state.py).\n  - **🐳 Langroid Docker image**, available, see instructions below.\n  - [**RecipientTool**](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Ftools\u002Frecipient_tool.py) enables (+ enforces) LLM to \nspecify an intended recipient when talking to 2 or more agents. \nSee [this test](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_recipient_tool.py) for example usage.\n  - **Example:** [Answer questions](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat-search.py) using Google Search + vecdb-retrieval from URL contents. \n  - **0.1.39:** [`GoogleSearchTool`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Ftools\u002Fgoogle_search_tool.py) to enable Agents (their LLM) to do Google searches via function-calling\u002Ftools.\n    See [this chat example](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Fchat-search.py) for how easy it is to add this tool to an agent.\n  - **Colab notebook** to try the quick-start examples: [![Open in Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb) \n  - **0.1.37:** Added [`SQLChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fsql_chat_agent.py) -- thanks to our latest contributor [Rithwik Babu](https:\u002F\u002Fgithub.com\u002Frithwikbabu)!\n  - Multi-agent Example: [Autocorrect chat](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Fautocorrect.py)\n- **July 2023:** \n  - **0.1.30:** Added [`TableChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Ftable_chat_agent.py) to \n    [chat](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdata-qa\u002Ftable_chat.py) with tabular datasets (dataframes, files, URLs): LLM generates Pandas code,\n    and code is executed using Langroid's tool\u002Ffunction-call mechanism. \n  - **Demo:** 3-agent system for Audience [Targeting](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fdemos\u002Ftargeting\u002Faudience-targeting\u002F).\n  - **0.1.27**: Added [support](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fcachedb\u002Fmomento_cachedb.py) \n    for [Momento Serverless Cache](https:\u002F\u002Fwww.gomomento.com\u002F) as an alternative to Redis.\n  - **0.1.24**: [`DocChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fdoc_chat_agent.py) \n    now [accepts](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fparsing\u002Fdocument_parser.py) PDF files or URLs.\n\n\u003C\u002Fdetails>\n\n# 🚀 Demo\nSuppose you want to extract structured information about the key terms \nof a commercial lease document. You can easily do this with Langroid using a two-agent system,\nas we show in the [langroid-examples](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat_multi_extract.py) repo.\n(See [this script](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat-multi-extract-local.py)\nfor a version with the same functionality using a local Mistral-7b model.)\nThe demo showcases just a few of the many features of Langroid, such as:\n- Multi-agent collaboration: `LeaseExtractor` is in charge of the task, and its LLM (GPT4) generates questions \nto be answered by the `DocAgent`.\n- Retrieval augmented question-answering, with **source-citation**: `DocAgent` LLM (GPT4) uses retrieval from a vector-store to \nanswer the `LeaseExtractor`'s questions, cites the specific excerpt supporting the answer. \n- Function-calling (also known as tool\u002Fplugin): When it has all the information it \nneeds, the `LeaseExtractor` LLM presents the information in a structured \nformat using a Function-call. \n\nHere is what it looks like in action \n(a pausable mp4 video is [here](https:\u002F\u002Fvimeo.com\u002F871429249)).\n\n![Demo](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flangroid_langroid_readme_41c5ecda578f.gif)\n\n\n# ⚡ Highlights\n(For a more up-to-date list see the \n[Updates\u002FReleases](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid?tab=readme-ov-file#-updatesreleases) \nsection above)\n- **Agents as first-class citizens:** The [Agent](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Freference\u002Fagent\u002Fbase\u002F#langroid.agent.base.Agent) class encapsulates LLM conversation state,\n  and optionally a vector-store and tools. Agents are a core abstraction in Langroid;\n  Agents act as _message transformers_, and by default provide 3 _responder_ methods, one corresponding to each entity: LLM, Agent, User.\n- **Tasks:** A [Task](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Freference\u002Fagent\u002Ftask\u002F) class wraps an Agent, and gives the agent instructions (or roles, or goals), \n  manages iteration over an Agent's responder methods, \n  and orchestrates multi-agent interactions via hierarchical, recursive\n  task-delegation. The `Task.run()` method has the same \n  type-signature as an Agent's responder's methods, and this is key to how \n  a task of an agent can delegate to other sub-tasks: from the point of view of a Task,\n  sub-tasks are simply additional responders, to be used in a round-robin fashion \n  after the agent's own responders.\n- **Modularity, Reusability, Loose coupling:** The `Agent` and `Task` abstractions allow users to design\n  Agents with specific skills, wrap them in Tasks, and combine tasks in a flexible way.\n- **LLM Support**: Langroid supports OpenAI LLMs as well as LLMs from hundreds of \nproviders ([local\u002Fopen](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F) or [remote\u002Fcommercial](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F)) via proxy libraries and local model servers\nsuch as [ollama](https:\u002F\u002Fgithub.com\u002Follama), [oobabooga](https:\u002F\u002Fgithub.com\u002Foobabooga\u002Ftext-generation-webui), \n  [LiteLLM](https:\u002F\u002Fdocs.litellm.ai\u002Fdocs\u002Fproviders) that in effect mimic the OpenAI API. See the [supported LLMs](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fsupported-models\u002F). \n- **Caching of LLM responses:** Langroid supports [Redis](https:\u002F\u002Fredis.com\u002Ftry-free\u002F) to cache LLM responses.\n- **Vector-stores**: [Qdrant](https:\u002F\u002Fqdrant.tech\u002F), [Chroma](https:\u002F\u002Fwww.trychroma.com\u002F), LanceDB, Pinecone, PostgresDB (PGVector), Weaviate are currently supported.\n  Vector stores allow for Retrieval-Augmented-Generation (RAG).\n- **Grounding and source-citation:** Access to external documents via vector-stores \n   allows for grounding and source-citation.\n- **Observability, Logging, Lineage:** Langroid generates detailed logs of multi-agent interactions and\n  maintains provenance\u002Flineage of messages, so that you can trace back\n  the origin of a message.\n- **[Tools\u002FPlugins\u002FFunction-calling](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002Fchat-agent-tool\u002F)**:\n  Langroid supports OpenAI's [function calling](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fgpt\u002Ffunction-calling), as\n  well as an equivalent `ToolMessage` mechanism which works with\n  any LLM, not just OpenAI's.\n  Function calling and tools have the same developer-facing interface, implemented\n  using [Pydantic](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002F),\n  which makes it very easy to define tools\u002Ffunctions and enable agents\n  to use them. Benefits of using Pydantic are that you never have to write\n  complex JSON specs for function calling, and when the LLM\n  hallucinates malformed JSON, the Pydantic error message is sent back to\n  the LLM so it can fix it.\n\n--- \n\n# ⚙️ Installation and Setup\n\n### Install `langroid`\nLangroid requires Python 3.11+. We recommend using a virtual environment.\nUse `pip` to install a bare-bones slim version of `langroid` (from PyPi) to your virtual \nenvironment:\n```bash\npip install langroid\n```\nThe core Langroid package lets you use OpenAI Embeddings models via their API. \nIf you instead want to use the `sentence-transformers` embedding models from HuggingFace, \ninstall Langroid like this: \n```bash\npip install \"langroid[hf-embeddings]\"\n```\nFor many practical scenarios, you may need additional optional dependencies:\n- To use various document-parsers, install langroid with the `doc-chat` extra:\n    ```bash\n    pip install \"langroid[doc-chat]\"\n    ```\n- For \"chat with databases\", use the `db` extra:\n    ```bash\n    pip install \"langroid[db]\"\n    ```\n- You can specify multiple extras by separating them with commas, e.g.:\n    ```bash\n    pip install \"langroid[doc-chat,db]\"\n    ```\n- To simply install _all_ optional dependencies, use the `all` extra (but note that this will result in longer load\u002Fstartup times and a larger install size):\n    ```bash\n    pip install \"langroid[all]\"\n    ```\n\u003Cdetails>\n\u003Csummary>\u003Cb>Optional Installs for using SQL Chat with a PostgreSQL DB \u003C\u002Fb>\u003C\u002Fsummary>\n\nIf you are using `SQLChatAgent` \n(e.g. the script [`examples\u002Fdata-qa\u002Fsql-chat\u002Fsql_chat.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdata-qa\u002Fsql-chat\u002Fsql_chat.py)),\nwith a postgres db, you will need to:\n\n- Install PostgreSQL dev libraries for your platform, e.g.\n  - `sudo apt-get install libpq-dev` on Ubuntu,\n  - `brew install postgresql` on Mac, etc.\n- Install langroid with the postgres extra, e.g. `pip install langroid[postgres]`\n  or `poetry add \"langroid[postgres]\"` or `poetry install -E postgres`,\n  (or the corresponding `uv` versions, e.g. `uv add \"langroid[postgres]\"`\n  or `uv pip install langroid[postgres]`).\n  If this gives you an error, try `pip install psycopg2-binary` in your virtualenv.\n\u003C\u002Fdetails>\n\n📝 If you get strange errors involving `mysqlclient`, try doing `pip uninstall mysqlclient` followed by `pip install mysqlclient`.\n\n### Claude Code Plugin (Optional)\n\nThis plugin provides two skills:\n\n- `langroid:patterns` - Your Claude Code agent can leverage this skill to produce\n  Langroid multi-agent code using proper design patterns.\n- `langroid:add-pattern` - The agent can use this skill to record new patterns it\n  learns, for future reference, either autonomously or when prompted by the user.\n\n**Step 1: Add the Langroid marketplace**\n\nFrom terminal:\n```bash\nclaude plugin marketplace add langroid\u002Flangroid\n```\n\nOr within Claude Code:\n```\n\u002Fplugin marketplace add langroid\u002Flangroid\n```\n\n**Step 2: Install the Langroid plugin**\n\nFrom terminal:\n```bash\nclaude plugin install langroid@langroid\n```\n\nOr within Claude Code:\n```\n\u002Fplugin install langroid@langroid\n```\n\nOnce installed, simply ask your Claude Code agent to implement Langroid patterns in\nnatural language, e.g.,\n\n> set up a Langroid agent so it uses the EditTool, and wrap it in a task that ends as soon as the tool is generated\n\nand it will automatically use the `langroid:patterns` skill to follow the right design pattern.\n\nYou can also ask Claude Code to record a new pattern when you discover one, e.g.,\n\n> record this as a new Langroid pattern for setting up MCP tools\n\n\n### Set up environment variables (API keys, etc)\n\nTo get started, all you need is an OpenAI API Key.\nIf you don't have one, see [this OpenAI Page](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fquickstart).\n(Note that while this is the simplest way to get started, Langroid works with practically any LLM, not just those from OpenAI. \nSee the guides to using [Open\u002FLocal LLMs](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F), \nand other [non-OpenAI](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F) proprietary LLMs.) \n\nIn the root of the repo, copy the `.env-template` file to a new file `.env`: \n```bash\ncp .env-template .env\n```\nThen insert your OpenAI API Key. \nYour `.env` file should look like this (the organization is optional \nbut may be required in some scenarios).\n```bash\nOPENAI_API_KEY=your-key-here-without-quotes\nOPENAI_ORGANIZATION=optionally-your-organization-id\n````\n\nAlternatively, you can set this as an environment variable in your shell\n(you will need to do this every time you open a new shell):\n```bash\nexport OPENAI_API_KEY=your-key-here-without-quotes\n```\n\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>Optional Setup Instructions (click to expand) \u003C\u002Fb>\u003C\u002Fsummary>\n\nAll of the following environment variable settings are optional, and some are only needed \nto use specific features (as noted below).\n\n- **Qdrant** Vector Store API Key, URL. This is only required if you want to use Qdrant cloud.\n  Alternatively [Chroma](https:\u002F\u002Fdocs.trychroma.com\u002F) or [LanceDB](https:\u002F\u002Flancedb.com\u002F) are also currently supported. \n  We use the local-storage version of Chroma, so there is no need for an API key.\n- **Redis** Password, host, port: This is optional, and only needed to cache LLM API responses\n  using Redis Cloud. Redis [offers](https:\u002F\u002Fredis.com\u002Ftry-free\u002F) a free 30MB Redis account\n  which is more than sufficient to try out Langroid and even beyond.\n  If you don't set up these, Langroid will use a pure-python \n  Redis in-memory cache via the [Fakeredis](https:\u002F\u002Ffakeredis.readthedocs.io\u002Fen\u002Flatest\u002F) library.\n- **Momento** Serverless Caching of LLM API responses (as an alternative to Redis). \n   To use Momento instead of Redis:\n  - enter your Momento Token in the `.env` file, as the value of `MOMENTO_AUTH_TOKEN` (see example file below),\n  - in the `.env` file set `CACHE_TYPE=momento` (instead of `CACHE_TYPE=redis` which is the default).\n- **GitHub** Personal Access Token (required for apps that need to analyze git\n  repos; token-based API calls are less rate-limited). See this\n  [GitHub page](https:\u002F\u002Fdocs.github.com\u002Fen\u002Fauthentication\u002Fkeeping-your-account-and-data-secure\u002Fmanaging-your-personal-access-tokens).\n- **Google Custom Search API Credentials:** Only needed to enable an Agent to use the `GoogleSearchTool`.\n  To use Google Search as an LLM Tool\u002FPlugin\u002Ffunction-call, \n  you'll need to set up \n  [a Google API key](https:\u002F\u002Fdevelopers.google.com\u002Fcustom-search\u002Fv1\u002Fintroduction#identify_your_application_to_google_with_api_key),\n  then [setup a Google Custom Search Engine (CSE) and get the CSE ID](https:\u002F\u002Fdevelopers.google.com\u002Fcustom-search\u002Fdocs\u002Ftutorial\u002Fcreatingcse).\n  (Documentation for these can be challenging, we suggest asking GPT4 for a step-by-step guide.)\n  After obtaining these credentials, store them as values of \n  `GOOGLE_API_KEY` and `GOOGLE_CSE_ID` in your `.env` file. \n  Full documentation on using this (and other such \"stateless\" tools) is coming soon, but \n  in the meantime take a peek at this [chat example](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Fchat-search.py), which \n  shows how you can easily equip an Agent with a `GoogleSearchtool`.\n  \n\n\nIf you add all of these optional variables, your `.env` file should look like this:\n```bash\nOPENAI_API_KEY=your-key-here-without-quotes\nGITHUB_ACCESS_TOKEN=your-personal-access-token-no-quotes\nCACHE_TYPE=redis # or momento\nREDIS_PASSWORD=your-redis-password-no-quotes\nREDIS_HOST=your-redis-hostname-no-quotes\nREDIS_PORT=your-redis-port-no-quotes\nMOMENTO_AUTH_TOKEN=your-momento-token-no-quotes # instead of REDIS* variables\nQDRANT_API_KEY=your-key\nQDRANT_API_URL=https:\u002F\u002Fyour.url.here:6333 # note port number must be included\nGOOGLE_API_KEY=your-key\nGOOGLE_CSE_ID=your-cse-id\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>Optional setup instructions for Microsoft Azure OpenAI(click to expand)\u003C\u002Fb>\u003C\u002Fsummary> \n\nWhen using Azure OpenAI, additional environment variables are required in the \n`.env` file.\nThis page [Microsoft Azure OpenAI](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fai-services\u002Fopenai\u002Fchatgpt-quickstart?tabs=command-line&pivots=programming-language-python#environment-variables)\nprovides more information, and you can set each environment variable as follows:\n\n- `AZURE_OPENAI_API_KEY`, from the value of `API_KEY`\n- `AZURE_OPENAI_API_BASE` from the value of `ENDPOINT`, typically looks like `https:\u002F\u002Fyour.domain.azure.com`.\n- For `AZURE_OPENAI_API_VERSION`, you can use the default value in `.env-template`, and latest version can be found [here](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fai-services\u002Fopenai\u002Fwhats-new#azure-openai-chat-completion-general-availability-ga)\n- `AZURE_OPENAI_DEPLOYMENT_NAME` is the name of the deployed model, which is defined by the user during the model setup \n- `AZURE_OPENAI_MODEL_NAME` Azure OpenAI allows specific model names when you select the model for your deployment. You need to put precisly the exact model name that was selected. For example, GPT-4 (should be `gpt-4-32k` or `gpt-4`).\n- `AZURE_OPENAI_MODEL_VERSION` is required if `AZURE_OPENAI_MODEL_NAME = gpt=4`, which will assist Langroid to determine the cost of the model  \n\u003C\u002Fdetails>\n\n---\n\n# 🐳 Docker Instructions\n\nWe provide a containerized version of the [`langroid-examples`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples) \nrepository via this [Docker Image](https:\u002F\u002Fhub.docker.com\u002Fr\u002Flangroid\u002Flangroid).\nAll you need to do is set up environment variables in the `.env` file.\nPlease follow these steps to setup the container:\n\n```bash\n# get the .env file template from `langroid` repo\nwget -O .env https:\u002F\u002Fraw.githubusercontent.com\u002Flangroid\u002Flangroid\u002Fmain\u002F.env-template\n\n# Edit the .env file with your favorite editor (here nano), and remove any un-used settings. E.g. there are \"dummy\" values like \"your-redis-port\" etc -- if you are not using them, you MUST remove them.\nnano .env\n\n# launch the container (the appropriate image for your architecture will be pulled automatically)\ndocker run -it --rm  -v .\u002F.env:\u002Flangroid\u002F.env langroid\u002Flangroid:latest\n\n# Use this command to run any of the scripts in the `examples` directory\npython examples\u002F\u003CPath\u002FTo\u002FExample.py> \n``` \n\n\n\n# 🎉 Usage Examples\n\nThese are quick teasers to give a glimpse of what you can do with Langroid\nand how your code would look. \n\n⚠️ The code snippets below are intended to give a flavor of the code\nand they are **not** complete runnable examples! For that we encourage you to \nconsult the [`langroid-examples`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples) \nrepository.\n\nℹ️\nThe various LLM prompts and instructions in Langroid\nhave been tested to work well with GPT-4 (and to some extent GPT-4o).\nSwitching to other LLMs (local\u002Fopen and proprietary) is easy (see guides mentioned above),\nand may suffice for some applications, but in general you may see inferior results\nunless you adjust the prompts and\u002For the multi-agent setup.\n\n\n📖 Also see the\n[`Getting Started Guide`](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002F)\nfor a detailed tutorial.\n\n\n\nClick to expand any of the code examples below.\nAll of these can be run in a Colab notebook:\n[![Open in Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb)\n\n\u003Cdetails>\n\u003Csummary> \u003Cb> Direct interaction with LLM \u003C\u002Fb> \u003C\u002Fsummary>\n\n```python\nimport langroid.language_models as lm\n\nmdl = lm.OpenAIGPT(\n    lm.OpenAIGPTConfig(\n        chat_model=lm.OpenAIChatModel.GPT4o, # or, e.g.  \"ollama\u002Fqwen2.5\"\n    ),\n)\n\nmessages = [\n  lm.LLMMessage(content=\"You are a helpful assistant\",  role=lm.Role.SYSTEM), \n  lm.LLMMessage(content=\"What is the capital of Ontario?\",  role=lm.Role.USER),\n]\n\nresponse = mdl.chat(messages, max_tokens=200)\nprint(response.message)\n```\nSee the guides to use\n([local\u002Fopen LLMs](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F) or [remote\u002Fcommercial LLMs](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F)).\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary> \u003Cb> Interaction with non-OpenAI LLM (local or remote) \u003C\u002Fb> \u003C\u002Fsummary>\nLocal model: if model is served at `http:\u002F\u002Flocalhost:8000`:\n\n```python\ncfg = lm.OpenAIGPTConfig(\n  chat_model=\"local\u002Flocalhost:8000\", \n  chat_context_length=4096\n)\nmdl = lm.OpenAIGPT(cfg)\n# now interact with it as above, or create an Agent + Task as shown below.\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary> \u003Cb> Define an agent, set up a task, and run it \u003C\u002Fb> \u003C\u002Fsummary>\n\n```python\nimport langroid as lr\n\nagent = lr.ChatAgent()\n\n# get response from agent's LLM, and put this in an interactive loop...\n# answer = agent.llm_response(\"What is the capital of Ontario?\")\n  # ... OR instead, set up a task (which has a built-in loop) and run it\ntask = lr.Task(agent, name=\"Bot\") \ntask.run() # ... a loop seeking response from LLM or User at each turn\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> Three communicating agents \u003C\u002Fb>\u003C\u002Fsummary>\n\nA toy numbers game, where when given a number `n`:\n- `repeater_task`'s LLM simply returns `n`,\n- `even_task`'s LLM returns `n\u002F2` if `n` is even, else says \"DO-NOT-KNOW\"\n- `odd_task`'s LLM returns `3*n+1` if `n` is odd, else says \"DO-NOT-KNOW\"\n\nEach of these `Task`s automatically configures a default `ChatAgent`.\n\n```python\nimport langroid as lr\nfrom langroid.utils.constants import NO_ANSWER\n\nrepeater_task = lr.Task(\n    name = \"Repeater\",\n    system_message=\"\"\"\n    Your job is to repeat whatever number you receive.\n    \"\"\",\n    llm_delegate=True, # LLM takes charge of task\n    single_round=False, \n)\n\neven_task = lr.Task(\n    name = \"EvenHandler\",\n    system_message=f\"\"\"\n    You will be given a number. \n    If it is even, divide by 2 and say the result, nothing else.\n    If it is odd, say {NO_ANSWER}\n    \"\"\",\n    single_round=True,  # task done after 1 step() with valid response\n)\n\nodd_task = lr.Task(\n    name = \"OddHandler\",\n    system_message=f\"\"\"\n    You will be given a number n. \n    If it is odd, return (n*3+1), say nothing else. \n    If it is even, say {NO_ANSWER}\n    \"\"\",\n    single_round=True,  # task done after 1 step() with valid response\n)\n```\nThen add the `even_task` and `odd_task` as sub-tasks of `repeater_task`, \nand run the `repeater_task`, kicking it off with a number as input:\n```python\nrepeater_task.add_sub_task([even_task, odd_task])\nrepeater_task.run(\"3\")\n```\n\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> Simple Tool\u002FFunction-calling example \u003C\u002Fb>\u003C\u002Fsummary>\n\nLangroid leverages Pydantic to support OpenAI's\n[Function-calling API](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fgpt\u002Ffunction-calling)\nas well as its own native tools. The benefits are that you don't have to write\nany JSON to specify the schema, and also if the LLM hallucinates a malformed\ntool syntax, Langroid sends the Pydantic validation error (suitably sanitized) \nto the LLM so it can fix it!\n\nSimple example: Say the agent has a secret list of numbers, \nand we want the LLM to find the smallest number in the list. \nWe want to give the LLM a `probe` tool\u002Ffunction which takes a\nsingle number `n` as argument. The tool handler method in the agent\nreturns how many numbers in its list are at most `n`.\n\nFirst define the tool using Langroid's `ToolMessage` class:\n\n\n```python\nimport langroid as lr\n\nclass ProbeTool(lr.agent.ToolMessage):\n  request: str = \"probe\" # specifies which agent method handles this tool\n  purpose: str = \"\"\"\n        To find how many numbers in my list are less than or equal to  \n        the \u003Cnumber> you specify.\n        \"\"\" # description used to instruct the LLM on when\u002Fhow to use the tool\n  number: int  # required argument to the tool\n```\n\nThen define a `SpyGameAgent` as a subclass of `ChatAgent`, \nwith a method `probe` that handles this tool:\n\n```python\nclass SpyGameAgent(lr.ChatAgent):\n  def __init__(self, config: lr.ChatAgentConfig):\n    super().__init__(config)\n    self.numbers = [3, 4, 8, 11, 15, 25, 40, 80, 90]\n\n  def probe(self, msg: ProbeTool) -> str:\n    # return how many numbers in self.numbers are less or equal to msg.number\n    return str(len([n for n in self.numbers if n \u003C= msg.number]))\n```\n\nWe then instantiate the agent and enable it to use and respond to the tool:\n\n```python\nspy_game_agent = SpyGameAgent(\n    lr.ChatAgentConfig(\n        name=\"Spy\",\n        vecdb=None,\n        use_tools=False, #  don't use Langroid native tool\n        use_functions_api=True, # use OpenAI function-call API\n    )\n)\nspy_game_agent.enable_message(ProbeTool)\n```\n\nFor a full working example see the\n[chat-agent-tool.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fquick-start\u002Fchat-agent-tool.py)\nscript in the `langroid-examples` repo.\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary> \u003Cb>Tool\u002FFunction-calling to extract structured information from text \u003C\u002Fb> \u003C\u002Fsummary>\n\nSuppose you want an agent to extract \nthe key terms of a lease, from a lease document, as a nested JSON structure.\nFirst define the desired structure via Pydantic models:\n\n```python\nfrom pydantic import BaseModel\nclass LeasePeriod(BaseModel):\n    start_date: str\n    end_date: str\n\n\nclass LeaseFinancials(BaseModel):\n    monthly_rent: str\n    deposit: str\n\nclass Lease(BaseModel):\n    period: LeasePeriod\n    financials: LeaseFinancials\n    address: str\n```\n\nThen define the `LeaseMessage` tool as a subclass of Langroid's `ToolMessage`.\nNote the tool has a required argument `terms` of type `Lease`:\n\n```python\nimport langroid as lr\n\nclass LeaseMessage(lr.agent.ToolMessage):\n    request: str = \"lease_info\"\n    purpose: str = \"\"\"\n        Collect information about a Commercial Lease.\n        \"\"\"\n    terms: Lease\n```\n\nThen define a `LeaseExtractorAgent` with a method `lease_info` that handles this tool,\ninstantiate the agent, and enable it to use and respond to this tool:\n\n```python\nclass LeaseExtractorAgent(lr.ChatAgent):\n    def lease_info(self, message: LeaseMessage) -> str:\n        print(\n            f\"\"\"\n        DONE! Successfully extracted Lease Info:\n        {message.terms}\n        \"\"\"\n        )\n        return json.dumps(message.terms.dict())\n    \nlease_extractor_agent = LeaseExtractorAgent()\nlease_extractor_agent.enable_message(LeaseMessage)\n```\n\nSee the [`chat_multi_extract.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat_multi_extract.py)\nscript in the `langroid-examples` repo for a full working example.\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> Chat with documents (file paths, URLs, etc) \u003C\u002Fb>\u003C\u002Fsummary>\n\nLangroid provides a specialized agent class `DocChatAgent` for this purpose.\nIt incorporates document sharding, embedding, storage in a vector-DB, \nand retrieval-augmented query-answer generation.\nUsing this class to chat with a collection of documents is easy.\nFirst create a `DocChatAgentConfig` instance, with a \n`doc_paths` field that specifies the documents to chat with.\n\n```python\nimport langroid as lr\nfrom langroid.agent.special import DocChatAgentConfig, DocChatAgent\n\nconfig = DocChatAgentConfig(\n  doc_paths = [\n    \"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FLanguage_model\",\n    \"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FN-gram_language_model\",\n    \"\u002Fpath\u002Fto\u002Fmy\u002Fnotes-on-language-models.txt\",\n  ],\n  vecdb=lr.vector_store.QdrantDBConfig(),\n)\n```\n\nThen instantiate the `DocChatAgent` (this ingests the docs into the vector-store):\n\n```python\nagent = DocChatAgent(config)\n```\nThen we can either ask the agent one-off questions,\n```python\nagent.llm_response(\"What is a language model?\")\n```\nor wrap it in a `Task` and run an interactive loop with the user:\n```python\ntask = lr.Task(agent)\ntask.run()\n```\n\nSee full working scripts in the \n[`docqa`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Ftree\u002Fmain\u002Fexamples\u002Fdocqa)\nfolder of the `langroid-examples` repo.\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> 🔥 Chat with tabular data (file paths, URLs, dataframes) \u003C\u002Fb>\u003C\u002Fsummary>\n\nUsing Langroid you can set up a `TableChatAgent` with a dataset (file path, URL or dataframe),\nand query it. The Agent's LLM generates Pandas code to answer the query, \nvia function-calling (or tool\u002Fplugin), and the Agent's function-handling method\nexecutes the code and returns the answer.\n\nHere is how you can do this:\n\n```python\nimport langroid as lr\nfrom langroid.agent.special import TableChatAgent, TableChatAgentConfig\n```\n\nSet up a `TableChatAgent` for a data file, URL or dataframe\n(Ensure the data table has a header row; the delimiter\u002Fseparator is auto-detected):\n```python\ndataset =  \"https:\u002F\u002Farchive.ics.uci.edu\u002Fml\u002Fmachine-learning-databases\u002Fwine-quality\u002Fwinequality-red.csv\"\n# or dataset = \"\u002Fpath\u002Fto\u002Fmy\u002Fdata.csv\"\n# or dataset = pd.read_csv(\"\u002Fpath\u002Fto\u002Fmy\u002Fdata.csv\")\nagent = TableChatAgent(\n    config=TableChatAgentConfig(\n        data=dataset,\n    )\n)\n```\nSet up a task, and ask one-off questions like this: \n\n```python\ntask = lr.Task(\n  agent, \n  name = \"DataAssistant\",\n  default_human_response=\"\", # to avoid waiting for user input\n)\nresult = task.run(\n  \"What is the average alcohol content of wines with a quality rating above 7?\",\n  turns=2 # return after user question, LLM fun-call\u002Ftool response, Agent code-exec result\n) \nprint(result.content)\n```\nOr alternatively, set up a task and run it in an interactive loop with the user:\n\n```python\ntask = lr.Task(agent, name=\"DataAssistant\")\ntask.run()\n``` \n\nFor a full working example see the \n[`table_chat.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Ftree\u002Fmain\u002Fexamples\u002Fdata-qa\u002Ftable_chat.py)\nscript in the `langroid-examples` repo.\n\n\n\u003C\u002Fdetails>\n\n---\n\n# ❤️ Thank you to our [supporters](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fstargazers)\n\nIf you like this project, please give it a star ⭐ and 📢 spread the word in your network or social media:\n\n[![Share on Twitter](https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Furl?style=social&url=https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid)](https:\u002F\u002Ftwitter.com\u002Fintent\u002Ftweet?text=Langroid%20is%20a%20powerful,%20elegant%20new%20framework%20to%20easily%20build%20%23LLM%20applications.%20You%20set%20up%20LLM-powered%20Agents%20with%20vector-stores,%20assign%20tasks,%20and%20have%20them%20collaboratively%20solve%20problems%20via%20message-transformations.%20https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid)\n[![Share on LinkedIn](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FShare%20on-LinkedIn-blue)](https:\u002F\u002Fwww.linkedin.com\u002FshareArticle?mini=true&url=https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid&title=Langroid:%20A%20Powerful,%20Elegant%20Framework&summary=Langroid%20is%20a%20powerful,%20elegant%20new%20framework%20to%20easily%20build%20%23LLM%20applications.%20You%20set%20up%20LLM-powered%20Agents%20with%20vector-stores,%20assign%20tasks,%20and%20have%20them%20collaboratively%20solve%20problems%20via%20message-transformations.)\n[![Share on Hacker News](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F-Share%20on%20Hacker%20News-orange)](https:\u002F\u002Fnews.ycombinator.com\u002Fsubmitlink?u=https%3A%2F%2Fgithub.com%2Flangroid%2Flangroid&t=Harness%20LLMs%20with%20Multi-Agent%20Programming)\n[![Share on Reddit](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F-Share%20on%20Reddit-blue)](https:\u002F\u002Fwww.reddit.com\u002Fsubmit?url=https%3A%2F%2Fgithub.com%2Flangroid%2Flangroid&title=Harness%20LLMs%20with%20Multi-Agent%20Programming)\n\nYour support will help build Langroid's momentum and community.\n\n# Langroid Co-Founders\n\n- [Prasad Chalasani](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fpchalasani\u002F) (IIT BTech\u002FCS, CMU PhD\u002FML; Independent ML Consultant)\n- [Somesh Jha](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fsomesh-jha-80208015\u002F) (IIT BTech\u002FCS, CMU PhD\u002FCS; Professor of CS, U Wisc at Madison)\n\n\n\n","\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flangroid_langroid_readme_cfee98aa6601.png\" alt=\"Logo\"\n        width=\"400\" align=\"center\">\n\u003C\u002Fdiv>\n\n\u003Cdiv align=\"center\">\n\n[![PyPI - Version](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Flangroid)](https:\u002F\u002Fpypi.org\u002Fproject\u002Flangroid\u002F)\n[![Downloads](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fdm\u002Flangroid)](https:\u002F\u002Fpypi.org\u002Fproject\u002Flangroid\u002F)\n[![Pytest](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fpytest.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fpytest.yml)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Flangroid\u002Flangroid\u002Fgraph\u002Fbadge.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Flangroid\u002Flangroid)\n[![Multi-Architecture DockerHub](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fdocker-publish.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Factions\u002Fworkflows\u002Fdocker-publish.yml)\n\n[![Static Badge](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDocumentation-blue?link=https%3A%2F%2Flangroid.github.io%2Flangroid%2F&link=https%3A%2F%2Flangroid.github.io%2Flangroid%2F)](https:\u002F\u002Flangroid.github.io\u002Flangroid)\n[![Open in Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb)\n[![Discord](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDiscord-%235865F2.svg?style=flat&logo=discord&logoColor=white)](https:\u002F\u002Fdiscord.gg\u002FZU36McDgDs)\n[![Substack](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSubstack-%23006f5c.svg?style=flat&logo=substack&logoColor=FF6719)](https:\u002F\u002Flangroid.substack.com\u002Fp\u002Flangroid-harness-llms-with-multi-agent-programming)\n\n\u003C\u002Fdiv>\n\n\u003Ch3 align=\"center\">\n  \u003Ca target=\"_blank\" \n    href=\"https:\u002F\u002Flangroid.github.io\u002Flangroid\u002F\" rel=\"dofollow\">\n      \u003Cstrong>文档\u003C\u002Fstrong>\u003C\u002Fa>\n  &middot;\n  \u003Ca target=\"_blank\" href=\"https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\" rel=\"dofollow\">\n      \u003Cstrong>示例仓库\u003C\u002Fstrong>\u003C\u002Fa>\n  &middot;\n  \u003Ca target=\"_blank\" href=\"https:\u002F\u002Fdiscord.gg\u002FZU36McDgDs\" rel=\"dofollow\">\n      \u003Cstrong>Discord\u003C\u002Fstrong>\u003C\u002Fa>\n  &middot;\n  \u003Ca target=\"_blank\" href=\"https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002FCONTRIBUTING.md\" rel=\"dofollow\">\n      \u003Cstrong>贡献指南\u003C\u002Fstrong>\u003C\u002Fa>\n\n  \u003Cbr \u002F>\n\u003C\u002Fh3>\n\n`Langroid` 是一个直观、轻量级、可扩展且基于原则的 Python 框架，由卡内基梅隆大学和威斯康星大学麦迪逊分校的研究人员开发，旨在轻松构建由大语言模型驱动的应用程序。用户只需设置智能体，为其配备可选组件（如大语言模型、向量存储以及工具或函数），分配任务，然后让这些智能体通过消息交互协作解决问题。这种多智能体范式受到 [Actor 模型](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FActor_model) 的启发（不过你无需了解该模型！）。\n\n`Langroid` 是一种全新的大语言模型应用开发方式，在简化开发者体验方面投入了大量思考；它不依赖 `Langchain` 或其他任何大语言模型框架，并且几乎可以与所有大语言模型配合使用（详见：https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fsupported-models\u002F）。\n\n🔥 ✨ 现已推出 Claude Code [插件](#claude-code-plugin-optional)，内置模式与最佳实践，可显著加速 Langroid 开发。\n\n🔥 阅读正在编写中的 [Langroid 架构概述](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fblog\u002F2024\u002F08\u002F15\u002Foverview-of-langroids-multi-agent-architecture-prelim\u002F) 以及 [Langroid 快速入门教程](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flangroid-tour\u002F)。\n\n🔥 MCP 支持：通过 Langroid 简单的 [MCP 工具适配器](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fmcp-tools\u002F)，任何 LLM 智能体都可以利用 MCP 服务器，将服务器提供的工具转换为 Langroid 的 `ToolMessage` 实例。\n\n📢 目前已有公司正在生产环境中使用或定制 Langroid。以下是其中一家公司的评价：\n\n>[Nullify](https:\u002F\u002Fwww.nullify.ai) 使用 AI 智能体进行安全软件开发，能够发现、优先排序并修复漏洞。在评估了 CrewAI、Autogen、LangChain、Langflow 等框架后，我们内部采用了 Langroid 的多智能体编排框架，并将其部署到生产环境。相比这些框架，Langroid 在配置简便性和灵活性方面表现更为出色。Langroid 的智能体和任务抽象设计直观、逻辑清晰，提供了极佳的开发体验。我们希望尽快将方案投入生产，而使用其他框架可能需要数周时间，但借助 Langroid，我们仅用几分钟就取得了良好效果。强烈推荐！\u003Cbr>—— Jacky Wong, Nullify 公司 AI 负责人\n\n\n🔥 LanceDB 团队发表了一篇关于 Langroid 的介绍性博客文章：[Langoid 多智能体编程框架](https:\u002F\u002Flancedb.substack.com\u002Fp\u002Flangoid-multi-agent-programming-framework)\n\n🔥 最新发表于《医疗人工智能》期刊（2024 年）的一篇论文，介绍了一个基于 Langroid 的多智能体 RAG 系统，用于药物警戒工作，详情请参阅博客文章：[面向药物警戒的 Malade 多智能体架构](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fblog\u002F2024\u002F08\u002F12\u002Fmalade-multi-agent-architecture-for-pharmacovigilance\u002F)\n\n\n我们欢迎社区贡献：有关如何参与贡献的想法，请参阅 [贡献指南](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002FCONTRIBUTING.md)。\n\n如果您正在构建大语言模型应用，或者希望为贵公司获得 Langroid 方面的帮助，亦或是希望优先开发针对贵公司特定场景的 Langroid 功能，请联系 [Prasad Chalasani](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fpchalasani\u002F) 进行咨询或开发合作：pchalasani@gmail.com。\n\n我们也接受来自 GitHub Sponsors 的赞助：[GitHub Sponsors](https:\u002F\u002Fgithub.com\u002Fsponsors\u002Flangroid)\n\n**有任何问题、反馈或想法吗？欢迎加入我们的 [Discord](https:\u002F\u002Fdiscord.gg\u002FZU36McDgDs) 讨论组！**\n\n# 使用 Langroid 编程的快速预览\n以下仅为示例，实际功能远不止于此，例如函数调用与工具集成、多智能体协作、结构化信息抽取、DocChatAgent（RAG）、SQLChatAgent、非 OpenAI 的本地或远程大语言模型等。更多内容请向下滚动或查阅文档。您还可以参考 Langroid 快速入门 [Colab 笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb)，其中逐步构建了一个使用 OpenAI ChatCompletion API 的双智能体信息抽取示例。此外，还有一个使用 OpenAI Assistants API 的版本：[链接](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F190Tk7t4AdY1P9F_NlZ33-YEoGnHweQQ0)。\n\n🔥 刚刚发布！[示例脚本](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat-multi-extract-local.py) 展示了如何利用 Langroid 的多智能体和工具，仅使用 **本地大语言模型**（Mistral-7b-instruct-v0.2），从文档中提取结构化信息。\n\n```python\nimport langroid as lr\nimport langroid.language_models as lm\n\n# 设置大语言模型\nllm_cfg = lm.OpenAIGPTConfig( # 或者使用 OpenAI Assistant API\n  # 任何可通过 OpenAI 兼容 API 调用的模型\n  chat_model=lm.OpenAIChatModel.GPT4o, # 或者例如 \"ollama\u002Fmistral\"\n)\n# 直接使用大语言模型\nmdl = lm.OpenAIGPT(llm_cfg)\nresponse = mdl.chat(\"安大略省的首都是哪里？\", max_tokens=10)\n\n# 在智能体中使用大语言模型\nagent_cfg = lr.ChatAgentConfig(llm=llm_cfg)\nagent = lr.ChatAgent(agent_cfg)\nagent.llm_response(\"中国的首都是哪里？\") \nresponse = agent.llm_response(\"那印度呢？\") # 维持对话状态 \n\n# 将智能体封装到任务中，以与用户（或其他智能体）进行交互式循环\ntask = lr.Task(agent, name=\"Bot\", system_message=\"你是一个有用的助手\")\ntask.run(\"你好\") # 从用户说“你好”开始\n\n# 两智能体聊天循环：教师智能体向学生智能体提问\nteacher_agent = lr.ChatAgent(agent_cfg)\nteacher_task = lr.Task(\n  teacher_agent, name=\"Teacher\",\n  system_message=\"\"\"\n    向你的学生提出简洁的数字问题，并给予反馈。 \n    先从一个问题开始。\n    \"\"\"\n)\nstudent_agent = lr.ChatAgent(agent_cfg)\nstudent_task = lr.Task(\n  student_agent, name=\"Student\",\n  system_message=\"简明扼要地回答老师的提问。\",\n  single_round=True,\n)\n\nteacher_task.add_sub_task(student_task)\nteacher_task.run()\n```\n\n# 🔥 更新\u002F发布\n\n\u003Cdetails>\n\u003Csummary> \u003Cb>点击展开\u003C\u002Fb>\u003C\u002Fsummary>\n\n- **2025年8月：**\n  - [0.59.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.59.0) 完成 Pydantic V2 迁移 - \n    验证速度提升5至50倍，采用现代Python编程模式，100%向后兼容。\n- **2025年7月：**\n  - [0.58.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.58.0) 集成 Crawl4AI - \n    使用 Playwright 对 JavaScript 为主的网站进行基于浏览器的网页爬取，无需 API 密钥（感谢 @abab-dev！）。\n  - [0.57.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.57.0) HTML 日志记录器，用于交互式任务可视化 - \n    自包含的 HTML 日志，支持折叠条目、自动刷新及持久化界面状态。\n- **2025年6月：**\n  - [0.56.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.56.0) `TaskTool`，用于将任务委派给子代理 - \n    允许代理创建具有特定工具和配置的子代理。\n  - [0.55.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.55.0) 基于事件的任务终止机制 `done_sequences` - \n    通过事件模式实现声明式的任务完成。\n  - [0.54.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.54.0) 支持 Portkey AI 网关 - 通过统一的 API 访问跨提供商的200多种模型，并提供缓存、重试和可观ability功能。\n- **2025年3–4月：**\n  - [0.53.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.53.0) 支持 MCP 工具。\n  - [0.52.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.52.0) 多模态支持，即允许 PDF、图像等输入进入 LLM。\n  - [0.51.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.51.0) `LLMPdfParser`，将 `GeminiPdfParser` 普遍化，直接使用 LLM 解析文档。\n  - [0.50.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.50.0) 基于结构感知的 Markdown 分块，分块内容由章节标题丰富。\n  - [0.49.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.49.0) 支持轻松切换到 LiteLLM 代理服务器。\n  - [0.48.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.48.0) Exa 爬虫、Markitdown 解析器。\n  - [0.47.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.47.0) 支持 Firecrawl URL 抓取器\u002F爬虫 - \n    感谢 @abab-dev。\n  - [0.46.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.46.0) 支持 LangDB LLM 网关 - 感谢 @MrunmayS。\n  - [0.45.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.45.0) 使用 `Marker` 进行 Markdown 解析 - 感谢 @abab-dev。\n  - [0.44.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.44.0) 延迟导入以减少启动时间。感谢 @abab-dev。\n- **2025年2月：**\n  - [0.43.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.43.0)：`GeminiPdfParser` 用于使用 Gemini LLM 解析 PDF - 感谢 @abab-dev。\n  - [0.42.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.42.0)：`markitdown` 解析器，用于处理 `pptx、xlsx、xls` 文件 \n    感谢 @abab-dev。\n  - [0.41.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.41.0)：`pinecone` 向量数据库（感谢 @coretado）， \n    `Tavily` 网络搜索（感谢 @Sozhan308），`Exa` 网络搜索（感谢 @MuddyHope）。\n  - [0.40.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.40.0)：`pgvector` 向量数据库。感谢 @abab-dev。\n  - [0.39.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.39.0)：`ChatAgentConfig.handle_llm_no_tool` 用于处理 LLM 忘记使用工具的情况。\n  - [0.38.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.38.0)：Gemini 嵌入 - 感谢 @abab-dev。\n  - [0.37.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.37.0)：新的 PDF 解析器：`docling`、`pymupdf4llm`。\n- **2025年1月：**\n  - [0.36.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.36.0)：Weaviate 向量数据库支持（感谢 @abab-dev）。\n  - [0.35.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.35.0)：除了最终答案外，还能捕获\u002F流式传输推理型 LLM（如 DeepSeek-R1、OpenAI o1）的推理内容。\n  - [0.34.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.34.0)：DocChatAgent 的分块增强，以提高检索效果。（与 @dfm88 合作）。\n  - [0.33.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.33.0) 从 Poetry 切换到 uv！（感谢 @abab-dev）。\n  - [0.32.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.32.0) 支持 DeepSeek v3。\n- **2024年12月：**\n  - [0.31.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.31.0) Azure OpenAI 嵌入。\n  - [0.30.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.30.0) Llama-cpp 嵌入（感谢 @Kwigg）。\n  - [0.29.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.29.0) 自定义 Azure OpenAI 客户端（感谢 \n    @johannestang）。\n  - [0.28.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.28.0) `ToolMessage`：新增 `_handler` 字段，用于覆盖 `request` 字段中的默认处理器方法名（感谢 @alexagr）。\n  - [0.27.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.27.0) 支持 OpenRouter。\n  - [0.26.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.26.0) 更新至最新 Chainlit 版本。\n  - [0.25.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.25.0) 为代理和用户响应实现真正的异步方法（感谢 @alexagr）。\n- **2024年11月：**\n  - **[0.24.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fstructured-output\u002F)**：\n     支持在兼容 LLM 上使用严格 JSON 模式输出格式的 `Agent`，以及 OpenAI 工具 API 的严格模式。\n    （感谢 @nilspalumbo）。\n  - **[0.23.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F#local-llms-hosted-on-glhfchat)**：\n      支持托管在 glhf.chat 上的 LLM（如 `Qwen2.5-Coder-32b-Instruct`）。\n  - **[0.22.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Flarge-tool-results\u002F)**：\n     提供可选参数以截断大型工具结果。\n  - **[0.21.0](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fgemini\u002F)** 直接通过 OpenAI 客户端支持 Gemini 模型，而非使用 LiteLLM。\n  - **[0.20.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.20.0)** 支持 ArangoDB 知识图谱。\n- **2024年10月：**\n  - **[0.18.0]** [LLMConfig.async_stream_quiet](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fasync-streaming\u002F) 标志，用于在异步 + 流式模式下关闭 LLM 输出。\n  - **[0.17.0]** 基于 XML 的工具，详见 [文档](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fxml-tools\u002F)。\n- **2024年9月：**\n  - **[0.16.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.16.0)** 支持 OpenAI 的 `o1-mini` 和 `o1-preview` 模型。\n  - **[0.15.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.15.0)** 支持 Cerebras API -- 在 Cerebras Cloud 上运行 llama-3.1 模型（推理速度非常快）。\n  - **[0.14.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.14.0)** `DocChatAgent` 使用互反排名融合（RRF）对不同方法检索到的分块进行排序。\n  - **[0.12.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.12.0)** `run_batch_task` 新选项 -- `stop_on_first_result` - 允许一旦有任一任务返回结果就终止批次任务。\n- **2024年8月：**\n  - **[0.11.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.11.0)** 多态的 `Task.run()、Task.run_async()`。\n  - **[0.10.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.10.0)** 允许工具处理器返回任意结果类型，包括其他工具。\n  - **[0.9.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.9.0)** 协调工具，用于信号各种任务状态，并在代理之间传递消息。\n  - **[0.7.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.7.0)** 支持 OpenAI 工具 API，包括多工具。\n- **2024年7月：**\n  - **[0.3.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.3.0)**：添加了来自 Qdrant 的 [FastEmbed](https:\u002F\u002Fqdrant.github.io\u002Ffastembed\u002Fqdrant\u002FUsage_With_Qdrant\u002F) 嵌入。\n- **2024年6月：**\n  - **0.2.0**：改进了 lineage 跟踪、细化了子任务配置，并新增了一种工具 `RewindTool`， \n    使代理能够“回退并重做”之前的某条消息（由于 lineage 跟踪，所有依赖该消息的消息都会被清除）。详细说明请参见 [此处](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.2.0)。\n- **2024年5月：**\n  - **更精简的 langroid**：所有文档解析器（如 pdf、doc、docx）以及大多数向量数据库（除 qdrant 外） \n    现在都成为可选\u002F额外依赖项，这有助于减小构建体积、脚本启动时间和安装时间。为了方便起见，提供了多种“附加组件”分组，例如 `doc-chat`、`db`（用于数据库相关依赖）。请参阅下方更新后的安装说明及文档。\n  - **工具的少样本示例**：在定义 [ToolMessage](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002Fchat-agent-tool\u002F#example-find-the-smallest-number-in-a-list) 时，过去可以包含一个名为 `examples` 的类方法，系统会随机从该列表中选取一个示例来生成 LLM 的单次示例。现在这一功能已改进，您可以直接提供一个示例列表，其中每个示例要么是工具实例，要么是一个元组（描述，工具实例），描述部分是引导 LLM 使用该工具的“思考过程”（详见 [文档](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002Fchat-agent-tool\u002F#example-find-the-smallest-number-in-a-list)）。在某些场景下，这能提高 LLM 生成工具的准确性。此外，现在不再随机选取示例，而是使用所有示例来生成少样本示例。     \n  - **无限循环检测**（位于 [0.2.0](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002F0ed30eb467b00d5eaf2933b577a4b2cc37de1aa1\u002Flangroid\u002Fagent\u002Ftask.py#L1121) 中）：针对循环长度不超过10的任务循环进行检测（可在 [`TaskConfig`](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Freference\u002Fagent\u002Ftask\u002F#langroid.agent.task.TaskConfig) 中配置）。仅检测“完全相同”的循环，而不检测实体反复说类似但不完全相同内容的“近似循环”。\n  - **“@”地址引用**：任何实体都可以通过名称直接引用其他实体，这些名称可以是代理的响应者（“llm”、“user”、“agent”）或子任务名称。这是一种比 `RecipientTool` 机制更简单的替代方案，但缺点是由于它不是工具，因此无法强制或提醒 LLM 显式指定收件人（在需要明确收件人的情况下）。\n  - **大幅改进的引用功能**（参见 [issue 477](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fissues\u002F477)） \n    在使用 `DocChatAgent` 时，引用的生成和显示得到了显著改善。\n  - `gpt-4o` 现已成为默认 LLM；更新测试和示例以适配该模型；使用与该模型对应的分词器。\n  - 通过 `litellm` 支持 `gemini 1.5 pro`。\n  - `QdrantDB`：更新以支持学习到的稀疏嵌入。\n- **2024年4月：**\n  - **0.1.236**：支持托管在 Groq 上的开源 LLM，例如指定 \n    `chat_model=\"groq\u002Fllama3-8b-8192\"`。\n      参见 [教程](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F)。\n  - **0.1.235**：`Task.run()、Task.run_async()、run_batch_tasks` 均增加了 `max_cost` 和 `max_tokens` 参数，当令牌或成本超过限制时将退出。结果中的 `ChatDocument.metadata` 现在包含一个 `status` 字段，该字段是一个代码，表示任务完成的原因。此外，`task.run()` 等方法也可以显式传入 `session_id` 字段，该字段用作在 Redis 缓存中查找各种设置的键。\n    目前仅用于查询“终止状态”——这使得可以通过 `task.kill()` 或类方法 `Task.kill_session(session_id)` 杀死正在运行的任务。\n    示例用法请参见 [tests\u002Fmain\u002Ftest_task.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_task.py) 中的 `test_task_kill`。\n  \n- **2024年3月：**\n  - **0.1.216**：改进了 `DocChatAgent` 的并发运行能力，详见\n    [`test_doc_chat_agent.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_doc_chat_agent.py)\n    特别是 `test_doc_chat_batch()`；\n    新增任务运行工具：[`run_batch_task_gen`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fbatch.py)，允许指定任务生成器，根据输入生成相应任务。\n  - **0.1.212**：ImagePdfParser：支持从基于图像的 PDF 中提取文本。\n    （这意味着 `DocChatAgent` 现在可以处理图像 PDF）。\n  - **0.1.194 - 0.1.211**：各种修复、改进和功能：\n    - 由于对 [相关性提取器](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.209) 的修复，RAG 性能（主要是召回率）得到大幅提升。\n    - `DocChatAgent` 的 [上下文窗口修复](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.208)。\n    - 通过 Litellm 支持 Anthropic\u002FClaude3。\n    - `URLLoader`：当 URL 不以 `.pdf`、`.docx` 等可识别的后缀结尾时，从头部检测文件时间。\n    - 各种 lancedb 集成修复。\n    - 根据是否可用 `sentence_transformer` 模块自动选择嵌入配置。\n    - 精简依赖项，将一些较重的依赖项设为可选，例如 `unstructured`、`haystack`、`chromadb`、`mkdocs`、`huggingface-hub`、`sentence-transformers`。\n    - 更容易从 `import langroid as lr` 进行顶层导入。\n    - 改善 JSON 检测，尤其是来自弱 LLM。\n- **2024年2月：**\n  - **0.1.193**：支持使用 Ollama 新推出的 OpenAI 兼容服务器运行本地 LLM： \n     只需指定 `chat_model=\"ollama\u002Fmistral\"`。详情请参见 [发布说明](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.193)。\n  - **0.1.183**：通过 [回调](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fcallbacks\u002Fchainlit.py) 添加了 Chainlit 支持。 \n   请参见 [示例](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Ftree\u002Fmain\u002Fexamples\u002Fchainlit)。\n- **2024年1月：**\n  - **0.1.175**\n    - [Neo4jChatAgent](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Ftree\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fneo4j) 用于与 Neo4j 知识图谱对话。\n      （感谢 [Mohannad](https:\u002F\u002Fgithub.com\u002FMohannadcse)！）。该代理使用工具查询 Neo4j 模式，并将用户查询转换为 Cypher 查询，\n      工具处理器执行这些查询，再将结果返回给 LLM 以生成自然语言响应（类似于 `SQLChatAgent` 的工作方式）。\n      请参阅使用该代理回答关于 Python 包依赖关系问题的 [示例脚本](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Ftree\u002Fmain\u002Fexamples\u002Fkg-chat)。\n    - 支持 `.doc` 文件解析（除 `.docx` 外）。\n    - 在 `OpenAIGPTConfig` 中指定可选的 [`formatter` 参数](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.171) ，以确保本地 LLM 的聊天格式准确。\n  - **[0.1.157](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.157)**：`DocChatAgentConfig` 新增了一个参数：`add_fields_to_content`，用于指定要插入到主 `content` 字段中的其他文档字段，以帮助提高检索效果。\n  - **[0.1.156](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.156)**：新增任务控制信号 PASS_TO、SEND_TO；VectorStore：对文档进行 Pandas 表达式计算；LanceRAGTaskCreator 创建一个由查询规划师、评论员和 RAG 代理组成的三代理 RAG 系统。\n- **2023年12月：**\n  - **0.1.154**：（详情请参见 [0.1.149](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.149) 和 [0.1.154](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.154) 的发布说明）。\n    - `DocChatAgent`：导入 Pandas 数据框并进行筛选。\n    - `LanceDocChatAgent` 利用 `LanceDB` 向量数据库进行高效的向量搜索、全文搜索和筛选。\n    - 改进了任务和多代理控制机制。\n    - `LanceRAGTaskCreator` 可创建一个由 `LanceFilterAgent` 组成的两代理系统，该代理负责决定过滤条件并改写查询发送给 RAG 代理。\n  - **[0.1.141](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.141)**：\n    API 简化以减少样板代码：自动选择可用的 OpenAI 模型（优先 gpt-4o），简化默认设置。\n    简化 `Task` 初始化，使用默认的 `ChatAgent`。\n- **2023年11月：**\n  - **[0.1.126](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Freleases\u002Ftag\u002F0.1.126)**：\n     OpenAIAssistant 代理：支持缓存。\n  - **0.1.117**：支持 OpenAI Assistant API 工具：函数调用、代码解释器和检索器（RAG）、文件上传。这些功能可与 Langroid 的任务编排无缝集成。\n    在文档准备就绪之前，建议查看以下使用示例：\n    \n    - **测试：**\n      - [test_openai_assistant.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant.py)\n      - [test_openai_assistant_async.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant_async.py)\n\n- **示例脚本：**\n      - [最基础的聊天应用](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Foai-asst-chat.py)\n      - [与代码解释器聊天](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Foai-code-chat.py)\n      - [带检索功能的聊天（RAG）](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Foai-retrieval-assistant.py)\n      - [双代理RAG聊天](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Foai-retrieval-2.py)\n  - **0.1.112:** [`OpenAIAssistant`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fopenai_assistant.py) 是 `ChatAgent` 的子类，它利用了全新的 OpenAI Assistant API。它可以作为 `ChatAgent` 的直接替代品使用，并依赖 Assistant API 来维护对话状态，同时借助持久化的线程和助手，在需要时重新连接到它们。示例：[`test_openai_assistant.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant.py)，[`test_openai_assistant_async.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_openai_assistant_async.py)\n  - **0.1.111:** 支持最新的 OpenAI 模型：`GPT4_TURBO`\n（示例用法参见 [test_llm.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_llm.py)）\n  - **0.1.110:** 从 OpenAI v0.x 升级到 v1.1.1（为迎接 Assistants API 等做准备）；由于 OpenAI 版本冲突，`litellm` 暂时被禁用。\n- **2023年10月：**\n  - **0.1.107:** `DocChatAgent` 重排序器：`rank_with_diversity`、`rank_to_periphery`（避免居中）。\n  - **0.1.102:** `DocChatAgentConfig.n_neighbor_chunks > 0` 允许返回匹配内容周围的上下文块。\n  - **0.1.101:** `DocChatAgent` 使用 `RelevanceExtractorAgent`，让 LLM 通过句子编号提取片段中的相关部分，相比 LangChain 在其 `LLMChainExtractor` 中采用的“逐句复述”方式（即完整写出所有相关句子），这种方法大大提升了速度并降低了成本。\n  - **0.1.100:** API 更新：现在只需一次导入即可访问 Langroid 的所有功能，例如 `import langroid as lr`。使用方法请参阅[文档](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002F)。\n  - **0.1.99:** 提供便捷的批处理函数，可在异步模式下同时对输入列表执行任务和代理方法。示例参见 [test_batch.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_batch.py)。\n  - **0.1.95:** 新增对 [Momento Serverless Vector Index](https:\u002F\u002Fdocs.momentohq.com\u002Fvector-index) 的支持。\n  - **0.1.94:** 新增对 [LanceDB](https:\u002F\u002Flancedb.github.io\u002Flancedb\u002F) 向量存储的支持——支持向量搜索、全文搜索和 SQL 查询。\n  - **0.1.84:** 新增 [LiteLLM](https:\u002F\u002Fdocs.litellm.ai\u002Fdocs\u002Fproviders)，现在 Langroid 可以与超过 100 家远程或本地 LLM 提供商一起使用！\n     使用指南请参见[这里](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F)。\n- **2023年9月：**\n  - **0.1.78:** 多个 Task、Agent 和 LLM 方法的异步版本；现在支持用于 LLM 函数调用、工具和结构化输出的嵌套 Pydantic 类。\n  - **0.1.76:** DocChatAgent：初步支持加载 `docx` 文件。\n  - **0.1.72:** 对 DocChatAgent 进行多项改进：采用更好的嵌入模型、混合搜索提升检索效果、优化 PDF 解析，并使用交叉编码器对检索结果进行重排序。\n  - **与本地 Llama 模型一起使用：** 请参阅教程[这里](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fblog\u002F2023\u002F09\u002F14\u002Fusing-langroid-with-local-llms\u002F)。\n  - **Langroid 博客\u002F通讯上线！** 第一篇文章在此——欢迎订阅以获取最新动态。\n  - **0.1.56:** 支持 Azure OpenAI。\n  - **0.1.55:** 改进了 [`SQLChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fsql\u002Fsql_chat_agent.py)，该代理在将自然语言翻译成 SQL 时能够高效地检索相关的模式信息。\n- **2023年8月：**\n  - 使用 Langroid 代理和任务编排的[层次化计算](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fexamples\u002Fagent-tree\u002F)示例。\n  - **0.1.51:** 支持全局状态，参见 [test_global_state.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_global_state.py)。\n  - **🐳 Langroid Docker 镜像** 已发布，具体说明见下文。\n  - [**RecipientTool**](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Ftools\u002Frecipient_tool.py) 能够使 LLM 在与两个或更多代理对话时指定目标接收者，并强制执行这一规则。\n    示例用法参见 [此测试](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Ftests\u002Fmain\u002Ftest_recipient_tool.py)。\n  - **示例：** 使用 Google 搜索 + 从 URL 内容中进行向量数据库检索来[回答问题](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat-search.py)。\n  - **0.1.39:** [`GoogleSearchTool`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Ftools\u002Fgoogle_search_tool.py)，使代理及其 LLM 能够通过函数调用\u002F工具的方式进行 Google 搜索。\n    示例聊天参见 [此处](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Fchat-search.py)，展示了将此工具添加到代理中是多么简单。\n  - **Colab 笔记本** 可用于尝试快速入门示例：[![在 Colab 中打开](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb)\n  - **0.1.37:** 新增了 [`SQLChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fsql_chat_agent.py)——感谢我们最新的贡献者 [Rithwik Babu](https:\u002F\u002Fgithub.com\u002Frithwikbabu)!\n  - 多代理示例：[自动纠错聊天](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Fautocorrect.py)\n- **2023年7月：**\n  - **0.1.30:** 新增了 [`TableChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Ftable_chat_agent.py)，用于与表格数据集（数据框、文件、URL）进行[聊天]：LLM 生成 Pandas 代码，然后通过 Langroid 的工具\u002F函数调用机制执行代码。\n  - **演示：** 面向受众的[定位](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fdemos\u002Ftargeting\u002Faudience-targeting\u002F)三代理系统。\n  - **0.1.27**: 新增对 [Momento Serverless Cache](https:\u002F\u002Fwww.gomomento.com\u002F) 的[支持](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fcachedb\u002Fmomento_cachedb.py)，作为 Redis 的替代方案。\n  - **0.1.24**: [`DocChatAgent`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fagent\u002Fspecial\u002Fdoc_chat_agent.py) 现在可以[接受](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Flangroid\u002Fparsing\u002Fdocument_parser.py) PDF 文件或 URL。\n\n\u003C\u002Fdetails>\n\n# 🚀 演示\n假设你想从一份商业租赁合同文档中提取关键术语的结构化信息。使用 Langroid 的双代理系统，你可以轻松实现这一点，正如我们在 [langroid-examples](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat_multi_extract.py) 仓库中所展示的那样。\n（请参阅 [此脚本](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat-multi-extract-local.py)，它使用本地的 Mistral-7b 模型实现了相同的功能。）\n该演示展示了 Langroid 的众多功能中的一部分，例如：\n- 多代理协作：`LeaseExtractor` 负责整个任务，其 LLM（GPT4）会生成问题，由 `DocAgent` 来回答。\n- 增强检索问答，并附有**来源引用**：`DocAgent` 的 LLM（GPT4）通过从向量存储中检索相关信息来回答 `LeaseExtractor` 提出的问题，并引用支持答案的具体段落。\n- 函数调用（也称为工具\u002F插件）：当 `LeaseExtractor` 收集到所需的所有信息后，它会通过函数调用来以结构化格式呈现这些信息。\n\n以下是实际运行效果\n（可暂停的 mp4 视频可在 [这里](https:\u002F\u002Fvimeo.com\u002F871429249) 观看）。\n\n![演示](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flangroid_langroid_readme_41c5ecda578f.gif)\n\n\n# ⚡ 亮点\n（如需更更新的列表，请参阅上方的 \n[更新\u002F发布](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid?tab=readme-ov-file#-updatesreleases) \n部分）\n- **代理作为一等公民：** [Agent](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Freference\u002Fagent\u002Fbase\u002F#langroid.agent.base.Agent) 类封装了 LLM 对话状态，\n  并可选择性地包含向量存储和工具。代理是 Langroid 中的核心抽象；\n  代理充当“消息转换器”，默认提供 3 种“响应者”方法，分别对应于 LLM、代理和用户三个实体。\n- **任务：** [Task](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Freference\u002Fagent\u002Ftask\u002F) 类包装了一个代理，并为其提供指令（或角色、目标），\n  管理代理响应者方法的迭代过程，\n  以及通过层次化、递归式的任务委派来协调多代理交互。`Task.run()` 方法与代理响应者方法具有相同的类型签名，这正是任务能够将子任务委派给其他代理的关键所在：从任务的角度来看，子任务只是额外的响应者，将在代理自身的响应者之后以轮转方式被调用。\n- **模块化、可重用性、松耦合：** `Agent` 和 `Task` 抽象允许用户设计具有特定技能的代理，将其封装在任务中，并以灵活的方式组合任务。\n- **LLM 支持：** Langroid 支持 OpenAI 的 LLM，也支持来自数百家提供商的 LLM（无论是[本地\u002F开源](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F)还是[远程\u002F商用](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F)），通过代理库和本地模型服务器实现，例如 [ollama](https:\u002F\u002Fgithub.com\u002Follama)、[oobabooga](https:\u002F\u002Fgithub.com\u002Foobabooga\u002Ftext-generation-webui)、\n  [LiteLLM](https:\u002F\u002Fdocs.litellm.ai\u002Fdocs\u002Fproviders)，它们实际上模拟了 OpenAI API。更多信息请参见 [支持的 LLM 列表](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fsupported-models\u002F)。\n- **LLM 响应缓存：** Langroid 支持使用 [Redis](https:\u002F\u002Fredis.com\u002Ftry-free\u002F) 缓存 LLM 响应。\n- **向量存储：** 目前支持 [Qdrant](https:\u002F\u002Fqdrant.tech\u002F)、[Chroma](https:\u002F\u002Fwww.trychroma.com\u002F)、LanceDB、Pinecone、PostgresDB (PGVector) 和 Weaviate。\n  向量存储可用于增强检索生成（RAG）。\n- **语境化与来源引用：** 通过向量存储访问外部文档，\n  可实现语境化和来源引用。\n- **可观测性、日志记录、溯源：** Langroid 会生成详细的多代理交互日志，\n  并维护消息的出处\u002F溯源信息，以便您可以追溯消息的来源。\n- **[工具\u002F插件\u002F函数调用](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002Fchat-agent-tool\u002F)**：\n  Langroid 支持 OpenAI 的 [函数调用](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fgpt\u002Ffunction-calling)，同时也支持一种等效的 `ToolMessage` 机制，该机制适用于任何 LLM，而不仅限于 OpenAI 的模型。\n  函数调用和工具拥有相同的开发者接口，基于 [Pydantic](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002F) 实现，\n  这使得定义工具\u002F函数并让代理使用它们变得非常容易。使用 Pydantic 的好处在于，您无需编写复杂的 JSON 规范来进行函数调用；而且当 LLM 生成格式错误的 JSON 时，Pydantic 会返回错误信息，促使 LLM 自行修正。\n\n---\n\n# ⚙️ 安装与设置\n\n### 安装 `langroid`\nLangroid 需要 Python 3.11 或更高版本。我们建议使用虚拟环境。\n使用 `pip` 将一个精简版的 `langroid`（来自 PyPI）安装到您的虚拟环境中：\n```bash\npip install langroid\n```\n核心 Langroid 包允许您通过 OpenAI 的 API 使用嵌入模型。\n如果您希望使用 HuggingFace 的 `sentence-transformers` 嵌入模型，则可以这样安装 Langroid：\n```bash\npip install \"langroid[hf-embeddings]\"\n```\n在许多实际场景中，您可能还需要一些可选依赖项：\n- 若要使用各种文档解析器，请安装带有 `doc-chat` 附加组件的 Langroid：\n    ```bash\n    pip install \"langroid[doc-chat]\"\n    ```\n- 对于“数据库聊天”，请使用 `db` 附加组件：\n    ```bash\n    pip install \"langroid[db]\"\n    ```\n- 您可以通过逗号分隔指定多个附加组件，例如：\n    ```bash\n    pip install \"langroid[doc-chat,db]\"\n    ```\n- 若要一次性安装所有可选依赖项，可以使用 `all` 附加组件（但请注意，这会导致加载\u002F启动时间更长且安装体积更大）：\n    ```bash\n    pip install \"langroid[all]\"\n    ```\n\u003Cdetails>\n\u003Csummary>\u003Cb>使用 PostgreSQL 数据库进行 SQL 聊天的可选安装\u003C\u002Fb>\u003C\u002Fsummary>\n\n如果您正在使用 `SQLChatAgent`（例如脚本 [`examples\u002Fdata-qa\u002Fsql-chat\u002Fsql_chat.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fdata-qa\u002Fsql-chat\u002Fsql_chat.py)），并且连接的是 PostgreSQL 数据库，您需要：\n\n- 为您的平台安装 PostgreSQL 开发库，例如：\n  - 在 Ubuntu 上运行 `sudo apt-get install libpq-dev`，\n  - 在 Mac 上运行 `brew install postgresql` 等。\n- 安装带有 postgres 附加组件的 Langroid，例如 `pip install langroid[postgres]`\n  或 `poetry add \"langroid[postgres]\"` 或 `poetry install -E postgres`，\n  （或者使用相应的 `uv` 版本，例如 `uv add \"langroid[postgres]\"`\n  或 `uv pip install langroid[postgres]`）。\n  如果出现错误，请尝试在您的虚拟环境中运行 `pip install psycopg2-binary`。\n\u003C\u002Fdetails>\n\n📝 如果遇到与 `mysqlclient` 相关的奇怪错误，请先运行 `pip uninstall mysqlclient`，然后再重新安装 `mysqlclient`。\n\n### Claude Code 插件（可选）\n\n此插件提供两种技能：\n\n- `langroid:patterns` - 您的 Claude Code 代理可以利用此技能，使用适当的设计模式生成 Langroid 多智能体代码。\n- `langroid:add-pattern` - 代理可以使用此技能记录它学到的新模式，供将来参考，无论是自主完成还是在用户提示下完成。\n\n**步骤 1：添加 Langroid 市场**\n\n在终端中：\n```bash\nclaude plugin marketplace add langroid\u002Flangroid\n```\n\n或在 Claude Code 中：\n```\n\u002Fplugin marketplace add langroid\u002Flangroid\n```\n\n**步骤 2：安装 Langroid 插件**\n\n在终端中：\n```bash\nclaude plugin install langroid@langroid\n```\n\n或在 Claude Code 中：\n```\n\u002Fplugin install langroid@langroid\n```\n\n安装完成后，只需用自然语言要求您的 Claude Code 代理实现 Langroid 模式，例如：\n\n> 设置一个 Langroid 代理，使其使用 EditTool，并将其封装在一个任务中，该任务在工具生成后立即结束\n\n它将自动使用 `langroid:patterns` 技能来遵循正确的设计模式。\n\n您还可以在发现新模式时，要求 Claude Code 记录下来，例如：\n\n> 将此记录为设置 MCP 工具的新 Langroid 模式\n\n\n### 设置环境变量（API 密钥等）\n\n要开始使用，您只需要一个 OpenAI API 密钥。\n如果您还没有，请参阅 [OpenAI 官网](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fquickstart)。\n（请注意，虽然这是最简单的入门方式，但 Langroid 几乎可以与任何 LLM 配合使用，而不仅仅是 OpenAI 的模型。\n请参阅关于使用 [开放\u002F本地 LLM](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F) 以及其他 [非 OpenAI](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F) 专有 LLM 的指南。）\n\n在仓库根目录下，将 `.env-template` 文件复制为新的 `.env` 文件：\n```bash\ncp .env-template .env\n```\n然后插入您的 OpenAI API 密钥。\n您的 `.env` 文件应如下所示（组织 ID 是可选的，但在某些情况下可能需要）：\n```bash\nOPENAI_API_KEY=your-key-here-without-quotes\nOPENAI_ORGANIZATION=optionally-your-organization-id\n```\n\n或者，您也可以在 shell 中设置此环境变量\n（每次打开新 shell 时都需要执行此操作）：\n```bash\nexport OPENAI_API_KEY=your-key-here-without-quotes\n```\n\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>可选设置说明（点击展开）\u003C\u002Fb>\u003C\u002Fsummary>\n\n以下所有环境变量设置均为可选，其中一些仅在使用特定功能时才需要（如下所述）。\n\n- **Qdrant** 向量存储 API 密钥、URL。这仅在您想使用 Qdrant 云服务时才需要。\n  或者，目前也支持 [Chroma](https:\u002F\u002Fdocs.trychroma.com\u002F) 和 [LanceDB](https:\u002F\u002Flancedb.com\u002F)。\n  我们使用 Chroma 的本地存储版本，因此无需 API 密钥。\n- **Redis** 密码、主机、端口：这是可选的，仅在使用 Redis Cloud 缓存 LLM API 响应时才需要。\n  Redis [提供](https:\u002F\u002Fredis.com\u002Ftry-free\u002F) 一个免费的 30MB Redis 账户，\n  这足以试用 Langroid，甚至超出其需求。\n  如果您不进行这些设置，Langroid 将使用纯 Python 的 Redis 内存缓存，\n  通过 [Fakeredis](https:\u002F\u002Ffakeredis.readthedocs.io\u002Fen\u002Flatest\u002F) 库实现。\n- **Momento** 用于缓存 LLM API 响应的无服务器服务（作为 Redis 的替代方案）。\n   若要使用 Momento 而不是 Redis：\n  - 在 `.env` 文件中输入您的 Momento 令牌，作为 `MOMENTO_AUTH_TOKEN` 的值（见下方示例文件），\n  - 在 `.env` 文件中将 `CACHE_TYPE=momento`（而不是默认的 `CACHE_TYPE=redis`）。\n- **GitHub** 个人访问令牌（对于需要分析 git 仓库的应用程序是必需的；\n  基于令牌的 API 调用速率限制较少）。请参阅此\n  [GitHub 页面](https:\u002F\u002Fdocs.github.com\u002Fen\u002Fauthentication\u002Fkeeping-your-account-and-data-secure\u002Fmanaging-your-personal-access-tokens)。\n- **Google 自定义搜索 API 凭证：** 仅在启用代理使用 `GoogleSearchTool` 时才需要。\n  要将 Google 搜索作为 LLM 工具\u002F插件\u002F函数调用使用，\n  您需要先设置\n  [Google API 密钥](https:\u002F\u002Fdevelopers.google.com\u002Fcustom-search\u002Fv1\u002Fintroduction#identify_your_application_to_google_with_api_key)，\n  然后 [设置 Google 自定义搜索引擎 (CSE) 并获取 CSE ID](https:\u002F\u002Fdevelopers.google.com\u002Fcustom-search\u002Fdocs\u002Ftutorial\u002Fcreatingcse)。\n  （这些文档可能比较复杂，建议向 GPT4 请求逐步指南。）\n  获取这些凭证后，将其作为 `GOOGLE_API_KEY` 和 `GOOGLE_CSE_ID` 的值存储在您的 `.env` 文件中。\n  关于如何使用此类“无状态”工具的完整文档即将发布，但在此期间，您可以查看此\n  [聊天示例](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002Fbasic\u002Fchat-search.py)，其中展示了如何轻松地为代理配备 `GoogleSearchtool`。\n  \n\n\n如果您添加了所有这些可选变量，您的 `.env` 文件应如下所示：\n```bash\nOPENAI_API_KEY=your-key-here-without-quotes\nGITHUB_ACCESS_TOKEN=your-personal-access-token-no-quotes\nCACHE_TYPE=redis # 或 momento\nREDIS_PASSWORD=your-redis-password-no-quotes\nREDIS_HOST=your-redis-hostname-no-quotes\nREDIS_PORT=your-redis-port-no-quotes\nMOMENTO_AUTH_TOKEN=your-momento-token-no-quotes # 替代 REDIS* 变量\nQDRANT_API_KEY=your-key\nQDRANT_API_URL=https:\u002F\u002Fyour.url.here:6333 # 注意必须包含端口号\nGOOGLE_API_KEY=your-key\nGOOGLE_CSE_ID=your-cse-id\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb>Microsoft Azure OpenAI 的可选设置说明（点击展开）\u003C\u002Fb>\u003C\u002Fsummary> \n\n在使用 Azure OpenAI 时，`.env` 文件中需要额外的环境变量。\n此页面 [Microsoft Azure OpenAI](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fai-services\u002Fopenai\u002Fchatgpt-quickstart?tabs=command-line&pivots=programming-language-python#environment-variables)\n提供了更多信息，您可以按如下方式设置每个环境变量：\n\n- `AZURE_OPENAI_API_KEY`，来自 `API_KEY` 的值\n- `AZURE_OPENAI_API_BASE` 来自 `ENDPOINT` 的值，通常看起来像 `https:\u002F\u002Fyour.domain.azure.com`。\n- 对于 `AZURE_OPENAI_API_VERSION`，您可以使用 `.env-template` 中的默认值，\n  最新版本可在 [这里](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fai-services\u002Fopenai\u002Fwhats-new#azure-openai-chat-completion-general-availability-ga) 找到。\n- `AZURE_OPENAI_DEPLOYMENT_NAME` 是已部署模型的名称，由用户在模型设置过程中定义。\n- `AZURE_OPENAI_MODEL_NAME` Azure OpenAI 允许在部署模型时指定特定的模型名称。\n  您需要准确填写所选的模型名称。例如，GPT-4（应为 `gpt-4-32k` 或 `gpt-4`）。\n- `AZURE_OPENAI_MODEL_VERSION` 是必需的，如果 `AZURE_OPENAI_MODEL_NAME = gpt-4`，\n  这将帮助 Langroid 确定模型的成本。\n\u003C\u002Fdetails>\n\n---\n\n# 🐳 Docker 使用说明\n\n我们通过这个 [Docker 镜像](https:\u002F\u002Fhub.docker.com\u002Fr\u002Flangroid\u002Flangroid) 提供了 [`langroid-examples`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples) 仓库的容器化版本。\n你只需要在 `.env` 文件中设置环境变量即可。请按照以下步骤来启动容器：\n\n```bash\n# 从 `langroid` 仓库获取 .env 文件模板\nwget -O .env https:\u002F\u002Fraw.githubusercontent.com\u002Flangroid\u002Flangroid\u002Fmain\u002F.env-template\n\n# 使用你喜欢的编辑器（这里以 nano 为例）编辑 .env 文件，并移除任何未使用的配置项。例如，文件中包含一些“占位符”值，如 “your-redis-port” 等——如果你不使用它们，请务必将其删除。\nnano .env\n\n# 启动容器（系统会自动拉取适合你架构的镜像）\ndocker run -it --rm  -v .\u002F.env:\u002Flangroid\u002F.env langroid\u002Flangroid:latest\n\n# 使用以下命令运行 `examples` 目录中的任意脚本\npython examples\u002F\u003CPath\u002FTo\u002FExample.py> \n```\n\n\n\n# 🎉 使用示例\n\n这些是快速预览，旨在让你了解使用 Langroid 可以做什么，以及你的代码会是什么样子。\n\n⚠️ 下面的代码片段仅用于展示代码风格，\n**并非完整的可运行示例**！为此，我们鼓励你参考 [`langroid-examples`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples) 仓库。\n\nℹ️\nLangroid 中的各种 LLM 提示和指令已经过测试，与 GPT-4（并在一定程度上与 GPT-4o）配合良好。\n切换到其他 LLM（本地\u002F开源或专有模型）非常容易（参见上述指南），对于某些应用场景可能已经足够，但通常情况下，除非调整提示或多智能体设置，否则结果可能会较差。\n\n\n📖 更多详细教程请参阅\n[`入门指南`](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fquick-start\u002F)。\n\n\n\n点击展开下面的任一代码示例。所有这些示例都可以在 Colab 笔记本中运行：\n[![在 Colab 中打开](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Flangroid\u002Flangroid\u002Fblob\u002Fmain\u002Fexamples\u002FLangroid_quick_start.ipynb)\n\n\u003Cdetails>\n\u003Csummary> \u003Cb> 直接与 LLM 交互 \u003C\u002Fb> \u003C\u002Fsummary>\n\n```python\nimport langroid.language_models as lm\n\nmdl = lm.OpenAIGPT(\n    lm.OpenAIGPTConfig(\n        chat_model=lm.OpenAIChatModel.GPT4o, # 或者，例如  \"ollama\u002Fqwen2.5\"\n    ),\n)\n\nmessages = [\n  lm.LLMMessage(content=\"You are a helpful assistant\",  role=lm.Role.SYSTEM), \n  lm.LLMMessage(content=\"What is the capital of Ontario?\",  role=lm.Role.USER),\n]\n\nresponse = mdl.chat(messages, max_tokens=200)\nprint(response.message)\n```\n请参阅相关指南以了解如何使用\n([本地\u002F开源 LLM](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Flocal-llm-setup\u002F) 或 [远程\u002F商用 LLM](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Ftutorials\u002Fnon-openai-llms\u002F))。\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary> \u003Cb> 与非 OpenAI LLM（本地或远程）交互 \u003C\u002Fb> \u003C\u002Fsummary>\n本地模型：如果模型在 `http:\u002F\u002Flocalhost:8000` 上提供服务：\n\n```python\ncfg = lm.OpenAIGPTConfig(\n  chat_model=\"local\u002Flocalhost:8000\", \n  chat_context_length=4096\n)\nmdl = lm.OpenAIGPT(cfg)\n# 现在可以像上面一样与其交互，或者按照下方所示创建 Agent + Task。\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary> \u003Cb> 定义一个智能体，设置任务并运行 \u003C\u002Fb> \u003C\u002Fsummary>\n\n```python\nimport langroid as lr\n\nagent = lr.ChatAgent()\n\n# 获取智能体 LLM 的响应，并将其放入交互式循环中...\n# answer = agent.llm_response(\"What is the capital of Ontario?\")\n  # ... 或者，改为设置一个任务（内置循环），并运行它\ntask = lr.Task(agent, name=\"Bot\") \ntask.run() # ... 每轮都会向 LLM 或用户寻求响应的循环\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> 三个相互通信的智能体 \u003C\u002Fb>\u003C\u002Fsummary>\n\n一个简单的数字游戏，当给定一个数字 `n` 时：\n- `repeater_task` 的 LLM 只需返回 `n`，\n- `even_task` 的 LLM 如果 `n` 是偶数则返回 `n\u002F2`，否则返回 “DO-NOT-KNOW”；\n- `odd_task` 的 LLM 如果 `n` 是奇数则返回 `3*n+1`，否则返回 “DO-NOT-KNOW”。\n\n每个 `Task` 都会自动配置一个默认的 `ChatAgent`。\n\n```python\nimport langroid as lr\nfrom langroid.utils.constants import NO_ANSWER\n\nrepeater_task = lr.Task(\n    name = \"Repeater\",\n    system_message=\"\"\"\n    Your job is to repeat whatever number you receive.\n    \"\"\",\n    llm_delegate=True, # LLM 负责处理任务\n    single_round=False, \n)\n\neven_task = lr.Task(\n    name = \"EvenHandler\",\n    system_message=f\"\"\"\n    You will be given a number. \n    If it is even, divide by 2 and say the result, nothing else.\n    If it is odd, say {NO_ANSWER}\n    \"\"\",\n    single_round=True,  # 任务在收到有效响应后完成\n)\n\nodd_task = lr.Task(\n    name = \"OddHandler\",\n    system_message=f\"\"\"\n    You will be given a number n. \n    If it is odd, return (n*3+1), say nothing else. \n    If it is even, say {NO_ANSWER}\n    \"\"\",\n    single_round=True,  # 任务在收到有效响应后完成\n)\n```\n\n然后将 `even_task` 和 `odd_task` 添加为 `repeater_task` 的子任务，\n并运行 `repeater_task`，以一个数字作为输入：\n```python\nrepeater_task.add_sub_task([even_task, odd_task])\nrepeater_task.run(\"3\")\n```\n\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> 简单的工具\u002F函数调用示例 \u003C\u002Fb>\u003C\u002Fsummary>\n\nLangroid 利用 Pydantic 支持 OpenAI 的\n[函数调用 API](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fgpt\u002Ffunction-calling)\n以及其自身的原生工具。这样做的好处是，你无需编写任何 JSON 来指定模式；此外，如果 LLM 生成了格式错误的工具调用语法，Langroid 会将经过适当清理的 Pydantic 验证错误发送回 LLM，以便其进行修正！\n\n简单示例：假设智能体有一个秘密数字列表，\n我们希望 LLM 找到该列表中的最小数字。我们想为 LLM 提供一个名为 `probe` 的工具\u002F函数，该工具接受一个数字 `n` 作为参数。智能体中的工具处理方法会返回其列表中小于等于 `n` 的数字数量。\n\n首先使用 Langroid 的 `ToolMessage` 类定义该工具：\n\n\n```python\nimport langroid as lr\n\nclass ProbeTool(lr.agent.ToolMessage):\n  request: str = \"probe\" # 指定由哪个智能体方法处理此工具\n  purpose: str = \"\"\"\n        To find how many numbers in my list are less than or equal to  \n        the \u003Cnumber> you specify.\n        \"\"\" # 描述用于指导 LLM 何时以及如何使用该工具\n  number: int  # 工具所需的参数\n```\n\n然后定义一个 `SpyGameAgent` 类，作为 `ChatAgent` 的子类，\n并添加一个名为 `probe` 的方法来处理该工具：\n\n```python\nclass SpyGameAgent(lr.ChatAgent):\n  def __init__(self, config: lr.ChatAgentConfig):\n    super().__init__(config)\n    self.numbers = [3, 4, 8, 11, 15, 25, 40, 80, 90]\n\n  def probe(self, msg: ProbeTool) -> str:\n    # 返回 self.numbers 中小于或等于 msg.number 的数字数量\n    return str(len([n for n in self.numbers if n \u003C= msg.number]))\n```\n\n接下来实例化该智能体，并启用其使用和响应工具的功能：\n\n```python\nspy_game_agent = SpyGameAgent(\n    lr.ChatAgentConfig(\n        name=\"间谍\",\n        vecdb=None,\n        use_tools=False, # 不使用 Langroid 原生工具\n        use_functions_api=True, # 使用 OpenAI 函数调用 API\n    )\n)\nspy_game_agent.enable_message(ProbeTool)\n```\n\n完整的工作示例请参阅 `langroid-examples` 仓库中的脚本\n[chat-agent-tool.py](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fquick-start\u002Fchat-agent-tool.py)。\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary> \u003Cb>通过工具\u002F函数调用从文本中提取结构化信息 \u003C\u002Fb> \u003C\u002Fsummary>\n\n假设您希望代理从租赁文件中提取租赁的关键条款，并将其表示为嵌套的 JSON 结构。首先，通过 Pydantic 模型定义所需的结构：\n\n```python\nfrom pydantic import BaseModel\nclass LeasePeriod(BaseModel):\n    start_date: str\n    end_date: str\n\n\nclass LeaseFinancials(BaseModel):\n    monthly_rent: str\n    deposit: str\n\nclass Lease(BaseModel):\n    period: LeasePeriod\n    financials: LeaseFinancials\n    address: str\n```\n\n然后，将 `LeaseMessage` 工具定义为 Langroid 的 `ToolMessage` 子类。请注意，该工具有一个名为 `terms` 的必填参数，类型为 `Lease`：\n\n```python\nimport langroid as lr\n\nclass LeaseMessage(lr.agent.ToolMessage):\n    request: str = \"lease_info\"\n    purpose: str = \"\"\"\n        收集商业租赁的相关信息。\n        \"\"\"\n    terms: Lease\n```\n\n接下来，定义一个 `LeaseExtractorAgent` 类，其中包含处理此工具的方法 `lease_info`，实例化该代理，并启用其使用和响应此工具的功能：\n\n```python\nclass LeaseExtractorAgent(lr.ChatAgent):\n    def lease_info(self, message: LeaseMessage) -> str:\n        print(\n            f\"\"\"\n        完成！成功提取了租赁信息：\n        {message.terms}\n        \"\"\"\n        )\n        return json.dumps(message.terms.dict())\n    \nlease_extractor_agent = LeaseExtractorAgent()\nlease_extractor_agent.enable_message(LeaseMessage)\n```\n\n完整的工作示例请参阅 `langroid-examples` 仓库中的脚本\n[`chat_multi_extract.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Fblob\u002Fmain\u002Fexamples\u002Fdocqa\u002Fchat_multi_extract.py)。\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> 与文档（文件路径、URL 等）进行聊天 \u003C\u002Fb>\u003C\u002Fsummary>\n\nLangroid 提供了一个专门的代理类 `DocChatAgent` 用于此目的。它集成了文档分片、嵌入、向量数据库存储以及检索增强的问答生成功能。使用此类与一组文档进行对话非常简单。首先创建一个 `DocChatAgentConfig` 实例，并设置 `doc_paths` 字段来指定要与之对话的文档。\n\n```python\nimport langroid as lr\nfrom langroid.agent.special import DocChatAgentConfig, DocChatAgent\n\nconfig = DocChatAgentConfig(\n  doc_paths = [\n    \"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FLanguage_model\",\n    \"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FN-gram_language_model\",\n    \"\u002Fpath\u002Fto\u002Fmy\u002Fnotes-on-language-models.txt\",\n  ],\n  vecdb=lr.vector_store.QdrantDBConfig(),\n)\n```\n\n然后实例化 `DocChatAgent`（这会将文档摄入向量数据库）：\n\n```python\nagent = DocChatAgent(config)\n```\n\n之后，我们可以向代理提出一次性问题：\n\n```python\nagent.llm_response(\"什么是语言模型？\")\n```\n\n或者将其包装在一个 `Task` 中，并与用户进行交互式循环：\n\n```python\ntask = lr.Task(agent)\ntask.run()\n```\n\n完整的可运行脚本请参阅 `langroid-examples` 仓库中\n[`docqa`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Ftree\u002Fmain\u002Fexamples\u002Fdocqa) 文件夹下的相关脚本。\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Cb> 🔥 与表格数据（文件路径、URL、数据框等）进行聊天 \u003C\u002Fb>\u003C\u002Fsummary>\n\n使用 Langroid，您可以设置一个 `TableChatAgent` 并为其提供数据集（文件路径、URL 或数据框），然后对其进行查询。代理的 LLM 会通过函数调用（或工具\u002F插件）生成 Pandas 代码来回答查询，而代理的函数处理方法则会执行这些代码并返回答案。\n\n以下是具体操作步骤：\n\n```python\nimport langroid as lr\nfrom langroid.agent.special import TableChatAgent, TableChatAgentConfig\n```\n\n为数据文件、URL 或数据框设置一个 `TableChatAgent`（确保数据表有标题行；分隔符会自动检测）：\n\n```python\ndataset =  \"https:\u002F\u002Farchive.ics.uci.edu\u002Fml\u002Fmachine-learning-databases\u002Fwine-quality\u002Fwinequality-red.csv\"\n\n\n# 或者 dataset = \"\u002Fpath\u002Fto\u002Fmy\u002Fdata.csv\"\n# 或者 dataset = pd.read_csv(\"\u002Fpath\u002Fto\u002Fmy\u002Fdata.csv\")\nagent = TableChatAgent(\n    config=TableChatAgentConfig(\n        data=dataset,\n    )\n)\n```\n\n设置一个任务，并像这样提出一次性问题：\n\n```python\ntask = lr.Task(\n  agent, \n  name = \"DataAssistant\",\n  default_human_response=\"\", # 避免等待用户输入\n)\nresult = task.run(\n  \"质量评分高于 7 的葡萄酒的平均酒精含量是多少？\",\n  turns=2 # 在用户提问、LLM 函数调用\u002F工具响应、代理代码执行结果后返回\n) \nprint(result.content)\n```\n\n或者，您也可以设置一个任务，并与用户进行交互式循环：\n\n```python\ntask = lr.Task(agent, name=\"DataAssistant\")\ntask.run()\n``` \n\n完整的工作示例请参阅 `langroid-examples` 仓库中的脚本\n[`table_chat.py`](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid-examples\u002Ftree\u002Fmain\u002Fexamples\u002Fdata-qa\u002Ftable_chat.py)。\n\n\n\u003C\u002Fdetails>\n\n---\n\n# ❤️ 感谢我们的 [支持者](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fstargazers)\n\n如果您喜欢这个项目，请给它点个赞 ⭐，同时在您的网络或社交媒体上分享它：\n\n[![分享到 Twitter](https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Furl?style=social&url=https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid)](https:\u002F\u002Ftwitter.com\u002Fintent\u002Ftweet?text=Langroid%20是%20一个%20强大%20且%20优雅%20的新%20框架，%20可以%20轻松%20构建%20%23LLM%20应用。%20您%20可以%20使用%20向量%20数据库%20设置%20LLM%20驱动%20的%20代理，%20分配%20任务，%20并通过%20消息%20转换%20协作%20解决问题。https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid)\n[![分享到 LinkedIn](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FShare%20on-LinkedIn-blue)](https:\u002F\u002Fwww.linkedin.com\u002FshareArticle?mini=true&url=https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid&title=Langroid：%20一个%20强大%20且%20优雅%20的%20框架&summary=Langroid%20是%20一个%20强大%20且%20优雅%20的新%20框架，%20可以%20轻松%20构建%20%23LLM%20应用。%20您%20可以%20设置%20LLM%20驱动%20的%20代理，%20使用%20向量%20数据库，%20分配%20任务，%20并通过%20消息%20转换%20协作%20解决问题。)\n[![分享到 Hacker News](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F-Share%20on%20Hacker%20News-orange)](https:\u002F\u002Fnews.ycombinator.com\u002Fsubmitlink?u=https%3A%2F%2Fgithub.com%2Flangroid%2Flangroid&t=Harness%20LLMs%20with%20Multi-Agent%20Programming)\n[![分享到 Reddit](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F-Share%20on%20Reddit-blue)](https:\u002F\u002Fwww.reddit.com\u002Fsubmit?url=https%3A%2F%2Fgithub.com%2Flangroid%2Flangroid&title=Harness%20LLMs%20with%20Multi-Agent%20Programming)\n\n您的支持将有助于推动 Langroid 的发展并壮大其社区。\n\n# Langroid 联合创始人\n\n- [普拉萨德·查拉萨尼](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fpchalasani\u002F)（印度理工学院本科\u002F计算机科学，卡内基梅隆大学博士\u002F机器学习；独立机器学习顾问）\n- [索梅什·贾](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fsomesh-jha-80208015\u002F)（印度理工学院本科\u002F计算机科学，卡内基梅隆大学博士\u002F计算机科学；威斯康星大学麦迪逊分校计算机科学教授）","# Langroid 快速上手指南\n\nLangroid 是一个直观、轻量且可扩展的 Python 框架，专为构建基于大语言模型（LLM）的应用而设计。它采用多智能体（Multi-Agent）协作范式，灵感源自 Actor 模型，让开发者能够轻松设置智能体、分配任务并使其通过消息交换协同解决问题。Langroid 不依赖 LangChain 等其他框架，支持几乎所有主流 LLM。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**：Linux, macOS 或 Windows\n*   **Python 版本**：Python 3.9 或更高版本（推荐 3.10+）\n*   **前置依赖**：\n    *   `pip` 包管理工具\n    *   （可选）API Key：如使用 OpenAI、Anthropic 等云端模型，需提前准备好对应的 API Key 并配置环境变量。\n\n> **国内开发者提示**：如果访问 PyPI 源较慢，建议使用国内镜像源进行安装（见下文安装步骤）。\n\n## 安装步骤\n\n### 1. 基础安装\n使用 pip 安装最新稳定版：\n\n```bash\npip install langroid\n```\n\n**推荐使用国内镜像源加速安装：**\n```bash\npip install langroid -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n### 2. 可选依赖\n根据您的需求，可能需要安装额外的组件（如向量数据库支持、特定解析器等）：\n\n```bash\n# 例如安装用于文档处理的额外依赖\npip install langroid[doc] -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 基本使用\n\n以下示例展示了 Langroid 的核心用法：配置 LLM、创建智能体（Agent）、封装任务（Task）以及实现多智能体协作。\n\n### 1. 直接调用 LLM\n最基础的用法是直接初始化模型并进行对话。\n\n```python\nimport langroid as lr\nimport langroid.language_models as lm\n\n# 配置 LLM (支持 OpenAI 兼容接口，也可替换为 \"ollama\u002Fmistral\" 等本地模型)\nllm_cfg = lm.OpenAIGPTConfig(\n  chat_model=lm.OpenAIChatModel.GPT4o, \n)\n\n# 直接使用 LLM\nmdl = lm.OpenAIGPT(llm_cfg)\nresponse = mdl.chat(\"What is the capital of Ontario?\", max_tokens=10)\nprint(response)\n```\n\n### 2. 创建智能体 (Agent)\n将 LLM 封装进智能体，智能体可以维护对话状态。\n\n```python\n# 配置智能体\nagent_cfg = lr.ChatAgentConfig(llm=llm_cfg)\nagent = lr.ChatAgent(agent_cfg)\n\n# 发起对话 (自动维护上下文)\nagent.llm_response(\"What is the capital of China?\") \nresponse = agent.llm_response(\"And India?\") \n```\n\n### 3. 运行交互式任务 (Task)\n将智能体包装成任务，以便与用户或其他智能体进行交互循环。\n\n```python\n# 定义任务\ntask = lr.Task(\n    agent, \n    name=\"Bot\", \n    system_message=\"You are a helpful assistant\"\n)\n\n# 启动任务 (用户输入 \"Hello\" 开始)\ntask.run(\"Hello\") \n```\n\n### 4. 多智能体协作示例\n这是一个经典的“老师 - 学生”场景：老师智能体提问，学生智能体回答。\n\n```python\n# 配置两个智能体\nteacher_agent = lr.ChatAgent(agent_cfg)\nstudent_agent = lr.ChatAgent(agent_cfg)\n\n# 定义老师任务\nteacher_task = lr.Task(\n  teacher_agent, \n  name=\"Teacher\",\n  system_message=\"\"\"\n    Ask your student concise numbers questions, and give feedback. \n    Start with a question.\n    \"\"\"\n)\n\n# 定义学生任务 (single_round=True 表示回答一次后暂停，等待老师反馈)\nstudent_task = lr.Task(\n  student_agent, \n  name=\"Student\",\n  system_message=\"Concisely answer the teacher's questions.\",\n  single_round=True,\n)\n\n# 建立子任务关系并运行\nteacher_task.add_sub_task(student_task)\nteacher_task.run()\n```\n\n通过以上步骤，您即可快速构建起基于 Langroid 的多智能体应用。更多高级功能（如工具调用、RAG、本地模型部署等）请参考官方文档或示例仓库。","某金融科技团队需要构建一个自动化系统，从每日海量的非结构化新闻和财报中提炼关键数据，并生成合规的投资风险报告。\n\n### 没有 langroid 时\n- **单点故障频发**：试图用单个大模型提示词（Prompt）完成“提取 - 分析 - 写作”全流程，常因上下文过长导致逻辑混乱或关键数据遗漏。\n- **调试黑盒化**：当输出结果出错时，无法定位是信息提取不准还是推理逻辑偏差，只能盲目调整庞大的提示词，效率极低。\n- **协作机制缺失**：难以让“数据员”和“风控专家”两个角色真正互动，往往需要编写复杂的胶水代码来串联多个独立的 API 调用。\n- **扩展性差**：若要增加“情感分析”环节，需重构整个单体脚本，代码耦合度高，维护成本随功能增加呈指数级上升。\n\n### 使用 langroid 后\n- **角色分工明确**：轻松定义“信息提取代理”和“风险分析代理”，前者专攻数据清洗，后者负责逻辑研判，通过消息传递协同工作，准确率显著提升。\n- **过程透明可控**：利用内置的对话日志，开发者可清晰看到两个代理如何交换信息、修正错误，快速定位并优化特定环节的指令。\n- **原生多智能体协作**：无需编写繁琐的状态机或回调函数，langroid 基于 Actor 模型天然支持代理间自动协商，复杂任务流变得简洁优雅。\n- **灵活热插拔**：新增“情感分析代理”只需几行代码即可加入现有网络，各模块独立运行互不干扰，系统迭代速度大幅加快。\n\nlangroid 通过将复杂的单体 AI 任务拆解为可协作的多智能体网络，让开发者能以极低的代码成本构建出高可靠、易维护的生产级应用。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flangroid_langroid_cfee98aa.png","Langroid","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Flangroid_c1f39d26.png",null,"https:\u002F\u002Fgithub.com\u002Flangroid",[81,85,89,93],{"name":82,"color":83,"percentage":84},"Python","#3572A5",99.4,{"name":86,"color":87,"percentage":88},"Makefile","#427819",0.3,{"name":90,"color":91,"percentage":92},"Shell","#89e051",0.1,{"name":94,"color":95,"percentage":92},"Dockerfile","#384d54",3950,366,"2026-04-02T18:37:44","MIT",1,"Linux, macOS, Windows","非必需（取决于所选 LLM，支持本地模型如 Ollama\u002FMistral 或云端 API）","未说明",{"notes":105,"python":106,"dependencies":107},"Langroid 是一个轻量级框架，不依赖 LangChain。它支持多种 LLM（包括 OpenAI、本地 Ollama、Gemini 等）。若使用本地大模型（如 Mistral-7b），需根据具体模型要求配置 GPU 和内存。项目已迁移至 uv 进行依赖管理，并完全兼容 Pydantic V2。支持 Docker 多架构部署。","3.8+",[108,109,110,111,112,113],"pydantic>=2.0","openai","litellm","tiktoken","numpy","requests",[15,13,26,14,54,53],[116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133],"agents","chatgpt","gpt","gpt-4","gpt4","language-model","llm","llm-agent","multi-agent-systems","openai-api","ai","llm-framework","llama","local-llm","function-calling","information-retrieval","rag","retrieval-augmented-generation","2026-03-27T02:49:30.150509","2026-04-06T06:52:03.351745",[137,142,147,152,157,162],{"id":138,"question_zh":139,"answer_zh":140,"source_url":141},12842,"导入 langroid 或初始化模型时加载速度很慢，有什么优化建议吗？","该问题已在相关 PR（#762）中得到解决。如果您仍遇到加载缓慢的问题，可以尝试对导入过程进行性能分析（profiling）以定位瓶颈。维护者建议用户尝试协助分析导入耗时，并关注后续的更新修复。","https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fissues\u002F407",{"id":143,"question_zh":144,"answer_zh":145,"source_url":146},12843,"使用本地部署的 LLM（如 Mistral-7B\u002FOllama）时出现'history is longer than the max chat context'错误或无响应，如何解决？","首先，尝试将超时时间（timeout）增加到例如 300 秒，因为本地服务器可能在默认超时时间内无法返回响应。其次，可以在终端运行 `ollama serve` 查看后端日志以获取更多上下文。此外，建议先测试纯聊天模式（非文档问答）以确保本地 LLM 设置正常，或更换其他文档和问题类型进行排查。","https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fissues\u002F338",{"id":148,"question_zh":149,"answer_zh":150,"source_url":151},12844,"如何在多轮对话中处理 LLM 未返回预期格式的工具调用（ResultTool）的情况？","可以通过实现 `handle_message_fallback` 静态方法来处理这种情况。当 LLM 没有返回可识别的工具消息时，该方法会被触发。您可以在其中编写逻辑，将消息转发给助手代理（使用 ForwardTool）或进行其他容错处理，从而确保多轮对话能继续进行而不中断。","https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fissues\u002F666",{"id":153,"question_zh":154,"answer_zh":155,"source_url":156},12845,"如何添加对 Marker PDF 解析器的支持以实现高效的逐页 Markdown 转换？","需要在 `document_parser.py` 中添加一个 `MarkerPDFParser` 类。重点在于实现高效的逐页 Markdown 转换功能（类似于 `pymupdf4llm` 的表现）。注意，相关的依赖项（如 docling）应作为可选依赖（extra\u002Foptional dependency）而非核心依赖添加到 `pyproject.toml` 中，并需在文档中清晰说明配置方法。","https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fissues\u002F707",{"id":158,"question_zh":159,"answer_zh":160,"source_url":161},12846,"使用本地 Mixtral 模型配合 Oobabooga 服务器时，Prompt 似乎未能发送给 LLM，如何排查？","确保 `api_base` 指向正确的 `\u002Fv1` 端点（例如端口 5000），并将 `api_key` 设置为 Oobabooga 所需的格式（如全 1 字符串）。如果直接调用 `mdl.chat` 单条消息成功但多条消息失败，请检查 `chat_context_length` 和 `max_output_tokens` 的配置是否合理。此外，增加 `timeout` 参数（例如设为 60）可以解决因本地模型推理慢导致的超时问题。","https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fissues\u002F346",{"id":163,"question_zh":164,"answer_zh":165,"source_url":156},12847,"docling 是必须安装的核心依赖吗？","不是。docling 已经被设计为额外\u002F可选依赖（extra\u002Foptional dependency），而不是核心依赖。如果在 `pyproject.toml` 的核心依赖列表中看到了它，那可能是误解或需要移除的部分，用户只需在需要时单独安装即可。",[167,172,177,182,187,192,197,202,207,212,217,222,227,232,237,242,247,252,257,262],{"id":168,"version":169,"summary_zh":170,"released_at":171},71500,"0.61.1","## 修复 MiniMax 模型的上下文长度\n\nPR [#1007](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F1007) 将所有 MiniMax 模型的上下文窗口大小修正为使用 API 层面的上限 204,800 个 token（而非模型原生架构限制的 196,608 个）。由于 Langroid 调用的是 MiniMax 的 API 而非自托管，因此采用 API 上限可以避免不必要的提示截断。\n\n此外，还修复了文档和示例脚本中关于“100 万上下文”的引用。","2026-03-25T21:27:27",{"id":173,"version":174,"summary_zh":175,"released_at":176},71501,"0.61.0","## 添加 MiniMax LLM 提供商支持\n\nPR [#1004](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F1004) 通过 MiniMax 的 OpenAI 兼容 API，为 [MiniMax](https:\u002F\u002Fwww.minimaxi.com\u002F) 语言模型添加了全面的支持。\n\n### 新特性\n\n- **支持 7 模型**：M2.7、M2.5、M2.1、M2 及其 `-highspeed` 变体，上下文长度最高可达 100 万 tokens\n- **标准提供商模式**：模型名称使用 `minimax\u002F` 前缀（例如 `minimax\u002FM2.7`），与 DeepSeek 和 Gemini 等现有提供商保持一致\n- **API 密钥通过 `MINIMAX_API_KEY` 环境变量配置**\n- **示例脚本**：`examples\u002Fbasic\u002Fchat-minimax.py`\n- **文档更新**：更新了教程和支持的模型文档\n\n### 使用方法\n\n```python\nimport langroid as lr\nimport langroid.language_models as lm\n\nllm_config = lm.OpenAIGPTConfig(chat_model=\"minimax\u002FM2.7\")\nagent = lr.ChatAgent(lr.ChatAgentConfig(llm=llm_config))\n```\n\n### 可用模型\n\n| 模型 | 上下文长度 |\n|-------|----------|\n| M2.7 \u002F M2.7-highspeed | 100 万 |\n| M2.5 \u002F M2.5-highspeed | 20.4 万 |\n| M2.1 \u002F M2.1-highspeed | 100 万 |\n| M2 | 100 万 |","2026-03-25T20:56:02",{"id":178,"version":179,"summary_zh":180,"released_at":181},71502,"0.60.3","## 修复 Gemini 模型后缀处理\n\nPR [#1001](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F1001) 修复了 `langroid\u002Flanguage_models\u002Fmodel_info.py` 中针对 Gemini 模型的模型名称后缀去除逻辑。\n\n### 变更内容\n\n扩展了后缀处理逻辑，能够正确去除 `-exp`、`-experimental` 和 `-latest` 后缀，同时保留基于分隔符的 `-preview` 处理方式，从而正确处理带日期的预览版本（例如 `gemini-2.5-flash-lite-preview-06-17`）。\n\n此举解决了 PR [#1000](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F1000) 带来的回归问题：原方案仅会精确匹配并移除尾部后缀，导致带有日期信息的预览版本 ID 被破坏。","2026-03-16T15:29:07",{"id":183,"version":184,"summary_zh":185,"released_at":186},71503,"0.60.2","## Gemini 上下文预检修复\n\n本次发布包含两项与 Langroid 本地上下文长度预检行为相关的修复。\n\n- PR [#997](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F997)：在模型信息查询过程中，规范化常见的 Gemini 模型别名及提供商前缀的预览名称；当 Langroid 回退到默认模型元数据时，会明确发出警告。\n- PR [#998](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F998)：将序列化的文件附件载荷纳入 `ChatAgent` 的上下文预检统计中，从而避免高附件请求（尤其是 Gemini 的 data URI 附件）被误认为本地零成本操作。\n\n这两项修复共同提升了 Langroid 对 Gemini 模型别名及文件附件请求的预检准确性。","2026-03-13T13:15:57",{"id":188,"version":189,"summary_zh":190,"released_at":191},71504,"0.60.1","## 带有 LRU 逐出策略的线程安全客户端缓存\n\nPR [#993](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F993) 在 `langroid\u002Flanguage_models\u002Fclient_cache.py` 中增强了客户端缓存，使其具备线程安全性和 LRU（最近最少使用）逐出机制。\n\n### 新特性\n\n- **线程安全**：所有缓存操作现在都由 `threading.RLock()` 保护，以防止在多线程环境中出现竞态条件。\n- **LRU 跟踪**：缓存条目会存储一个单调递增的最后使用时间戳，并在每次访问时更新。\n- **`prune_cache(max_age_seconds)`**：新增方法，用于移除超过指定年龄的过期客户端条目。\n- **辅助函数**：`_get_cached_client()` 和 `_store_client()` 封装了缓存访问逻辑，确保一致的锁机制和时间戳管理。\n\n这些改进适用于所有缓存的客户端获取方法：`get_openai_client()`、`get_async_openai_client()`、`get_groq_client()`、`get_async_groq_client()`、`get_cerebras_client()` 和 `get_async_cerebras_client()`。","2026-03-13T11:59:21",{"id":193,"version":194,"summary_zh":195,"released_at":196},71505,"0.60.0","## 添加 Seltz 网络搜索集成\n\nPR [#994](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F994) 在现有网络搜索引擎提供商（Google、DuckDuckGo、Exa、Tavily）的基础上，新增了对 [Seltz](https:\u002F\u002Fseltz.io) 的支持。\n\n### 新增内容\n\n- `langroid\u002Fparsing\u002Fweb_search.py` 中的 `seltz_search()` 函数 — 调用 Seltz API 并以 `WebSearchResult` 对象的形式返回结果\n- `langroid\u002Fagent\u002Ftools\u002Fseltz_search_tool.py` 中的 `SeltzSearchTool` — 一种无状态工具，智能体可启用该工具来执行 Seltz 搜索\n- 示例脚本 `examples\u002Fbasic\u002Fchat-search-seltz.py` — 展示了一个使用 SeltzSearchTool 的聊天机器人\n- 文档 `docs\u002Fnotes\u002Fseltz_search.md` — 包含 API 密钥配置、安装和使用说明的设置指南\n\n### 安装\n\n```bash\npip install \"langroid[seltz]\"\n```\n\n需要设置 `SELTZ_API_KEY` 环境变量。\n\n### 详情\n\n有关完整用法，请参阅 [Seltz 搜索工具文档](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fseltz_search\u002F)。","2026-03-12T22:13:38",{"id":198,"version":199,"summary_zh":200,"released_at":201},71506,"0.59.39","## 支持 OpenAI HTTP 客户端配置的异步客户端工厂\n\nPR [#990](https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F990) 对 `OpenAIGPTConfig` 中的 `http_client_factory` 模式进行了增强，使其同时支持同步和异步 HTTP 客户端。\n\n### 新功能\n\n工厂函数现在支持两种模式：\n\n1. **单个客户端**（现有）：返回一个 `httpx.Client` — 异步客户端会自动创建。\n2. **客户端元组**（新增）：返回 `(httpx.Client, httpx.AsyncClient)` — 两个客户端按原样使用。\n\n这使得用户可以在保持完全向后兼容性的同时，以相同的设置（例如代理、SSL 证书）配置同步和异步客户端。\n\n### 详情\n\n请参阅更新后的文档：[OpenAI HTTP 客户端配置](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fopenai-http-client\u002F)","2026-02-28T20:19:34",{"id":203,"version":204,"summary_zh":205,"released_at":206},71507,"0.59.38","修复工具参数序列化为空（`None` → `\"{}\"`）的问题，该问题会导致在 Vertex AI 上使用 Gemini 模型时出现 `INVALID_ARGUMENT` 错误（#988）。","2026-02-26T18:39:28",{"id":208,"version":209,"summary_zh":210,"released_at":211},71508,"0.59.37","处理 OpenAI GPT 流式传输中的空增量：https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F987","2026-02-24T01:58:01",{"id":213,"version":214,"summary_zh":215,"released_at":216},71509,"0.59.36","为 gpt-5.1-chat 和 gpt-5.2-chat 模型添加模型信息。","2026-02-23T16:11:33",{"id":218,"version":219,"summary_zh":220,"released_at":221},71510,"0.59.35","## Fix streaming tool calls for Gemini models (#985)\n\nFixed a bug where tool calling was broken for `gemini-3-flash` in streaming mode. The `extra_content` field in `OpenAIToolCall` was not being properly preserved during stream delta aggregation. (Thanks @alexagr)\n\n## Fix README rendering on PyPI (#984)\n\nFixed PyPI README rendering issues by replacing GitHub-specific emoji shortcodes with Unicode emojis, converting relative image paths to absolute URLs, and converting relative links to absolute GitHub URLs. (Thanks @AtharvaJaiswal005)\n\n## Test improvements (#982)\n\nMarked flaky LLM tool-use test (`test_openai_assistant_fn_tool`) with `xfail` and improved assertion logic to correctly distinguish between function call and text response modes.","2026-02-22T14:39:21",{"id":223,"version":224,"summary_zh":225,"released_at":226},71511,"0.59.34","## Configurable context overflow strategy (#967, #974)\n\nAdded a `context_overflow_strategy` option to `ChatAgentConfig` for handling message history that exceeds the model's context length. Two strategies are available:\n\n- **`\"truncate\"`** (default): Truncates content of early messages while preserving all messages in the sequence. Maintains backward compatibility and the alternating message structure required by LLM APIs.\n- **`\"drop_turns\"`**: Drops complete conversation turns (a USER message and all responses until the next USER message). More aggressive but cleaner — particularly useful for voice agents with limited context models (e.g., `llama-3-8b` with 8192 tokens), where individual messages are already short and truncation is ineffective.\n\n```python\nconfig = lr.ChatAgentConfig(\n    context_overflow_strategy=\"drop_turns\",  # or \"truncate\" (default)\n    ...\n)\n```\n\n## Cleaner OpenAI API error logging (#975)\n\nOpenAI API errors (authentication, bad request, rate limits, etc.) are now logged without a full Python traceback, since these errors originate server-side and a local stack trace adds no diagnostic value. Network-level errors (`APIConnectionError`, `APITimeoutError`) still include the full traceback to aid in diagnosing local issues.\n\n## Minor fixes\n\n- Fixed defensive check for empty\u002Fmissing `choices` in OpenAI API response parsing (#975)\n- Formatting cleanup in inline reasoning tests (#977)\n- Updated `llms*.txt` documentation files","2026-02-11T17:39:26",{"id":228,"version":229,"summary_zh":230,"released_at":231},71512,"0.59.33","## Support inline reasoning in streaming responses (#973)\n\nAdded support for handling inline reasoning content in streaming LLM responses, for models that embed thinking\u002Freasoning inside the main content stream (e.g., using `\u003Cthink>...\u003C\u002Fthink>` delimiters) rather than in a separate reasoning field.\n\n### Key Changes\n\n- **Added `extra_content` field to `OpenAIToolCall`**: New optional field to store additional metadata from tool calls, with updated `from_dict()` and `api_dict()` methods\n- **Implemented inline reasoning splitting**: New `_split_inline_reasoning()` static method that separates reasoning tokens from text tokens based on configurable delimiters, tracking state across streaming chunks\n- **Enhanced streaming event processing**: Updated `_process_stream_event()` and `_process_stream_event_async()` to route split tokens to correct streamers (TEXT vs REASONING) with proper state tracking\n- **Updated Ruff**: Bumped pre-commit ruff version from v0.14.14 to v0.15.0","2026-02-09T13:06:25",{"id":233,"version":234,"summary_zh":235,"released_at":236},71513,"0.59.32","## Security Fix\n\n**Fix CVE-2025-46724 bypass in TableChatAgent sanitization**\n\nThe previous fix for CVE-2025-46724 could be bypassed due to missing validation of attribute access. Attackers could access dunder attributes (`__init__`, `__globals__`, `__builtins__`) to reach Python builtins and execute arbitrary code.\n\n### Exploit Vector (now blocked)\n```python\ndf.add_prefix(\"__import__('os').system('cmd')#\").T.groupby(\n    by=df.__init__.__globals__['__builtins__']['eval']\n)\n```\n\n### Fix\nAdded `visit_Attribute()` to the AST validator that blocks:\n- Dunder attributes (`__*__`) like `__init__`, `__globals__`, `__builtins__`\n- Private attributes (`_*`) as defense-in-depth\n\n### Impact\n- **Affected**: Users of `TableChatAgent` with `full_eval=False` (the default) processing untrusted input\n- **Severity**: Critical (RCE)\n- **Action**: Upgrade to 0.59.32 immediately\n\nNormal pandas expressions continue to work as expected. This fix is transparent to legitimate usage.\n\nSee: https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fsecurity\u002Fadvisories\u002FGHSA-x34r-63hx-w57f","2026-02-01T19:23:58",{"id":238,"version":239,"summary_zh":240,"released_at":241},71514,"0.59.31","## Add reasoning parameter to LLM response callbacks (#965)\n\nThis release adds support for passing chain-of-thought reasoning from LLMs (like DeepSeek R1, Claude extended thinking) to UI callbacks.\n\n### Features\n\n- **Reasoning in callbacks**: `show_llm_response` and `finish_llm_stream` callbacks now receive a `reasoning` parameter containing the LLM's chain-of-thought reasoning (when available)\n\n- **Chainlit integration**: Reasoning is automatically displayed as a nested message with a \"💭 Reasoning\" label in Chainlit UIs\n\n- **Backward compatible**: Existing custom callbacks without the `reasoning` parameter continue to work - uses signature inspection to only pass reasoning if supported\n\n### Documentation\n\n- Added \"Displaying Reasoning in UI Callbacks\" section to [reasoning-content.md](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Freasoning-content\u002F) with examples for custom callback implementations\n\nThanks to @alexagr for the initial PR adding the reasoning parameter!","2026-01-29T21:15:51",{"id":243,"version":244,"summary_zh":245,"released_at":246},71515,"0.59.30","## Message Routing Configuration\n\nThis release introduces and documents the `recognize_recipient_in_content` configuration option for controlling text-based message routing in multi-agent systems.\n\n### What's New\n\n- **Renamed config option**: `content_based_routing` → `recognize_recipient_in_content` for clarity and consistency with `TaskConfig.recognize_string_signals`\n- **Fixed OpenAIAssistant**: Now properly honors `recognize_recipient_in_content=False` (previously ignored the setting)\n- **Added tests**: New test coverage for `recognize_recipient_in_content` with both `TO[recipient]:` and JSON `{\"recipient\": ...}` patterns\n- **New documentation**: Added `docs\u002Fnotes\u002Fmessage-routing.md` covering:\n  - Orchestration tools (SendTool, etc.) as the recommended routing approach\n  - Text-based routing as an alternative\n  - How to disable all text-based routing\n\n### Configuration Options\n\n| Setting | Location | Controls |\n|---------|----------|----------|\n| `recognize_string_signals` | `TaskConfig` | Parsing of `DONE`, `PASS`, etc. |\n| `recognize_recipient_in_content` | `ChatAgentConfig` | Parsing of `TO[recipient]:` and JSON recipient patterns |\n\nTo disable all text-based routing:\n\n```python\nagent = ChatAgent(ChatAgentConfig(\n    recognize_recipient_in_content=False,\n))\ntask = Task(agent, config=TaskConfig(\n    recognize_string_signals=False,\n))\n```\n\nBased on PR #958 by @alexagr with refinements in PR #961.","2026-01-29T00:00:32",{"id":248,"version":249,"summary_zh":250,"released_at":251},71516,"0.59.29","## Thought Signatures Preserved in Message History\n\nModels like **Gemini 3 Flash** and **Amazon Nova** embed reasoning within inline thought tags (e.g. `\u003Cthinking>...\u003C\u002Fthinking>`) in their responses. Previously, these tags were stripped when extracting the reasoning, causing the model to lose context of its own thought process across conversation turns.\n\n### What's New\n\n- Added `message_with_reasoning` field to `LLMResponse` and `content_with_reasoning` field to `ChatDocument`\n- When inline thought tags are extracted, the original text is preserved and used in message history\n- Models that provide reasoning via a separate API field (DeepSeek, o1, etc.) are unaffected\n\n### Bug Fixes\n\n- **Targeted fix**: `message_with_reasoning` is now only set when `get_reasoning_final()` actually extracts inline tags — not whenever reasoning is non-empty. This prevents unnecessary duplication and avoids silently ignoring content modifications for models with separate reasoning fields.\n- **Test fix**: Pinned `tavily-mcp` to v0.2.12 in tests (v0.2.14+ has broken npm dependencies)\n\n### Credits\n\nBased on PR #959 by @alexagr with additional fixes.\n\n**Full PR**: https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fpull\u002F962","2026-01-28T16:59:59",{"id":253,"version":254,"summary_zh":255,"released_at":256},71517,"0.59.28","## Vertex AI Support for Gemini Models\n\nThis release adds support for Google Vertex AI's OpenAI-compatible endpoint for Gemini models.\n\n### New Features\n\n- **Vertex AI support**: Use Gemini models through Vertex AI by setting a custom `api_base` in `OpenAIGPTConfig` or via the new `GEMINI_API_BASE` environment variable\n- **`GEMINI_API_BASE` env var**: New environment variable for configuring the Gemini API endpoint (e.g., for Vertex AI), following the existing `GEMINI_API_KEY` pattern\n\n### Bug Fixes\n\n- **Prevent `OPENAI_API_BASE` leaking into Gemini**: The `OPENAI_API_BASE` env var (commonly used for local proxies) no longer inadvertently overrides the Gemini endpoint. Only explicitly-set `api_base` values or `GEMINI_API_BASE` are honored for Gemini models.\n- **Replace deprecated `parseString`**: Updated `langroid\u002Fparsing\u002Fagent_chats.py` to use `parse_string` instead of the deprecated `parseString` method from pyparsing\n\n### Documentation\n\n- Added Vertex AI setup and usage guide to [docs\u002Fnotes\u002Fgemini.md](https:\u002F\u002Flangroid.github.io\u002Flangroid\u002Fnotes\u002Fgemini\u002F)\n\n### Usage\n\n**Via environment variable (recommended for Vertex AI):**\n```bash\nexport GEMINI_API_KEY=$(gcloud auth print-access-token)\nexport GEMINI_API_BASE=https:\u002F\u002Fus-central1-aiplatform.googleapis.com\u002Fv1beta1\u002Fprojects\u002Fmy-project\u002Flocations\u002Fus-central1\u002Fendpoints\u002Fopenapi\n```\n\n**Via config:**\n```python\nimport langroid.language_models as lm\n\nconfig = lm.OpenAIGPTConfig(\n    chat_model=\"gemini\u002Fgemini-2.0-flash\",\n    api_base=\"https:\u002F\u002Fus-central1-aiplatform.googleapis.com\u002Fv1beta1\u002Fprojects\u002Fmy-project\u002Flocations\u002Fus-central1\u002Fendpoints\u002Fopenapi\",\n)\n```\n\n---\nThanks to @alexagr for the original PR (#954, #955)","2026-01-28T12:47:35",{"id":258,"version":259,"summary_zh":260,"released_at":261},71518,"0.59.27","### Fixed\r\n\r\n- **Respect user-provided API parameters**: Removed overly aggressive parameter filtering that silently dropped params like `reasoning_effort` for models added to `MODEL_INFO`. The library now trusts user configuration and lets the API validate parameter support. (#956 - thanks @alexagr)\r\n","2026-01-22T15:02:59",{"id":263,"version":264,"summary_zh":265,"released_at":266},71519,"0.59.26","## What's Changed\n\n### Improvements\n\n#### Callback API Enhancement: Separate content and tools_content (#952, #945)\n\nThe `show_llm_response` and `finish_llm_stream` callbacks now include separate `content` and `tools_content` parameters:\n\n- `content`: Always contains the text message generated by the model\n- `tools_content`: Contains serialized functions\u002Ftools if present, empty string otherwise\n\n**Why this matters:** Previously, `content` mixed text messages with JSON-serialized tool calls. This caused issues for applications using callbacks for purposes like text-to-speech, where tool call JSON was incorrectly processed as regular text.\n\n**Backward compatible:** The `tools_content` parameter defaults to an empty string, so existing callback implementations continue to work.\n\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Flangroid\u002Flangroid\u002Fcompare\u002F0.59.25...0.59.26","2026-01-16T15:17:26"]