Recent Releases of agentica

agentica - v1.0.10

v1.0.10

修复后的效果: ✅ 推理内容完整且无重复 ✅ 流式和非流式响应的推理内容一致 ✅ 正确处理大量小 chunk 的累积(如 deepseek-r1 的reasoning chunks) ✅ 支持各种推理模型(o1、deepseek-r1、gemini-2.5-pro 等)

Full Changelog: https://github.com/shibing624/agentica/compare/1.0.7...1.0.10

- Python
Published by shibing624 about 1 year ago

agentica - v1.0.6

v1.0.6

Support Model Context Protocol (MCP) Tools

This module provides a client implementation for the Model Context Protocol (MCP), allowing you to easily integrate MCP servers with your Agentica agents.

Features

  • Support for stdio, SSE, and StreamableHttp transport modes
  • Explicit parameter names for each transport type
  • Async context manager-based API for easy resource management
  • Tool caching for improved performance
  • Automatic tool registration with your agents

Installation

Make sure you have the mcp package installed:

bash pip install mcp

Basic Usage

Using the McpTool Class

The McpTool class is the primary way to integrate MCP services with your Agentica agents:

```python from agentica import Agent, OpenAIChat from agentica.tools.mcp_tool import McpTool from agentica import ShellTool

For SSE transport (direct connection to running server)

mcptool = McpTool( url="http://localhost:8081/sse", ssetimeout=5.0, ssereadtimeout=300.0 )

For StreamableHttp transport

mcptool = McpTool( url="http://localhost:8000/mcp", ssetimeout=5.0, ssereadtimeout=300.0 )

For stdio transport (launches a subprocess)

mcptool = McpTool( command="python path/to/your/mcpserver.py" )

Use with an agent

async with mcptool: agent = Agent( model=OpenAIChat(model="gpt-4o-mini"), tools=[ShellTool(), mcptool] )

await agent.aprint_response("Use the weather tool to check the forecast for Beijing")

```

Using Low-Level MCPClient and Server Classes

For more control, you can directly use the MCPClient and server classes:

```python import asyncio from agentica.mcp.client import MCPClient from agentica.mcp.server import MCPServerStdio, MCPServerSse, MCPServerStreamableHttp from datetime import timedelta

async def stdioexample(): """Example using stdio transport""" server = MCPServerStdio( name="MathTools", params={ "command": "python", "args": ["path/to/your/mcpserver.py"], "env": {"VAR": "value"} } )

async with MCPClient(server=server) as client:
    # List available tools
    tools = await client.list_tools()
    print(f"Available tools: {[tool.name for tool in tools]}")

    # Call a tool
    result = await client.call_tool("add", {"a": 5, "b": 7})
    text_result = client.extract_result_text(result)
    print(f"5 + 7 = {text_result}")

async def sseexample(): """Example using SSE transport""" server = MCPServerSse( name="WeatherService", params={ "url": "http://localhost:8081/sse", "headers": {"Authorization": "Bearer your-token"}, # Optional "timeout": 5.0, # HTTP request timeout "sseread_timeout": 300.0 # SSE connection timeout } )

async with MCPClient(server=server) as client:
    # Use client as in stdio example
    tools = await client.list_tools()
    result = await client.call_tool("get_weather", {"city": "Beijing"})
    print(client.extract_result_text(result))

async def streamablehttpexample(): """Example using StreamableHttp transport""" server = MCPServerStreamableHttp( name="WeatherService", params={ "url": "http://localhost:8000/mcp", "headers": {"Authorization": "Bearer your-token"}, # Optional "timeout": timedelta(seconds=5), # HTTP request timeout "ssereadtimeout": timedelta(seconds=300), # Connection timeout "terminateonclose": True # Whether to terminate on close } )

async with MCPClient(server=server) as client:
    # Use client as in other examples
    tools = await client.list_tools()
    result = await client.call_tool("get_weather", {"city": "Beijing"})
    print(client.extract_result_text(result))

if name == "main": asyncio.run(stdioexample()) asyncio.run(sseexample()) asyncio.run(streamablehttpexample()) ```

McpTool Configuration Options

The McpTool class supports several configuration options:

Transport Options

You must provide one of these to specify the transport method:

  • stdio_command: Command string to run the MCP server via stdio transport
  • sse_server_url: URL of the SSE endpoint for SSE transport
  • streamable_http_url: URL of the StreamableHttp endpoint
  • server_params: Directly provide StdioServerParameters for stdio transport
  • session: Directly provide an initialized ClientSession

SSE and StreamableHttp Configuration

For SSE and StreamableHttp transports, you can configure:

  • sse_headers: HTTP headers for the connection
  • sse_timeout: HTTP request timeout in seconds (default: 5.0)
  • sse_read_timeout: Connection timeout in seconds (default: 300.0)
  • terminate_on_close: Whether to terminate on close (StreamableHttp only, default: True)

Tool Filtering

You can filter which tools are exposed to your agent:

  • include_tools: List of tool names to include (if None, includes all)
  • exclude_tools: List of tool names to exclude

Other Options

  • env: Environment variables to pass to the server process (for stdio transport)

Example

```python

Create an McpTool with SSE transport

from agentica.tools.mcp_tool import McpTool

mcptool = McpTool( url="http://localhost:8081/sse", sseheaders={"Authorization": "Bearer token123"}, includetools=["getweather", "getforecast"], excludetools=["admin_tool"] )

Create an McpTool with StreamableHttp transport

mcptool = McpTool( url="http://localhost:8000/mcp", sseheaders={"Authorization": "Bearer token123"}, includetools=["getweather", "getforecast"], excludetools=["admin_tool"] )

Create an McpTool with stdio transport

mcptool = McpTool( command="python weatherserver.py --port 8081", env={"APIKEY": "yourapikey"}, includetools=["get_weather"] ) ```

Backward Compatibility

The McpTool class still supports environment variables for backward compatibility:

```python from agentica.tools.mcp_tool import McpTool

Using environment variables for SSE configuration

env = { "MCPSERVERURL": "http://localhost:8081/sse", "MCPSERVERHEADERS": '{"Authorization": "Bearer token123"}', "MCPSERVERTIMEOUT": "5", "MCPSERVERREAD_TIMEOUT": "300" }

mcp_tool = McpTool(env=env) ```

However, using the direct parameters is recommended for clarity and type safety.

MCP Server Implementation

If you're implementing your own MCP server, you can use the FastMCP class from the mcp package:

```python from mcp.server.fastmcp import FastMCP from fastapi import FastAPI

Create server

mcp = FastMCP("My MCP Server", host="0.0.0.0", port=8000)

Define a tool

@mcp.tool() def get_weather(city: str) -> str: """Get weather for a city""" # Implementation here return f"Weather for {city}: Sunny, 25°C"

Run the server

if name == "main": # Use 'stdio', 'sse', or 'streamable-http' transport mcp.run(transport="streamable-http") ```

Examples

Check out the examples directory for more complete examples:

  • examples/41_mcp_stdio_demo.py: Demonstrates how to use MCP with stdio transport
  • examples/42_mcp_sse_server.py: A simple MCP server with SSE transport
  • examples/42_mcp_sse_client.py: Demonstrates how to connect to an MCP SSE server
  • examples/44_mcp_streamable_http_server.py: A simple MCP server with StreamableHttp transport
  • examples/44_mcp_streamable_http_client.py: Demonstrates how to connect to an MCP StreamableHttp server

What's Changed

  • Add MseeP.ai badge by @lwsinclair in https://github.com/shibing624/agentica/pull/17
  • Add MseeP.ai badge by @lwsinclair in https://github.com/shibing624/agentica/pull/16

New Contributors

  • @lwsinclair made their first contribution in https://github.com/shibing624/agentica/pull/17

Full Changelog: https://github.com/shibing624/agentica/compare/1.0.3...1.0.6

- Python
Published by shibing624 about 1 year ago

agentica - 1.0.0

v1.0.0

Model Context Protocol (MCP) Tools

This module provides a client implementation for the Model Context Protocol (MCP), allowing you to easily integrate MCP servers with your Agentica agents.

Features

  • Support for both stdio and SSE transport modes
  • Explicit parameter names for each transport type
  • Async context manager-based API for easy resource management
  • Tool caching for improved performance
  • Automatic tool registration with your agents

Installation

Make sure you have the mcp package installed:

bash pip install mcp

Basic Usage

Using the McpTool Class

The McpTool class is the primary way to integrate MCP services with your Agentica agents:

```python from agentica import Agent, OpenAIChat from agentica.tools.mcp_tool import McpTool from agentica import ShellTool

For SSE transport (direct connection to running server)

mcptool = McpTool( sseserverurl="http://localhost:8081/sse", ssetimeout=5.0, ssereadtimeout=300.0 )

For stdio transport (launches a subprocess)

mcptool = McpTool( stdiocommand="python path/to/your/mcp_server.py" )

Use with an agent

async with mcptool: agent = Agent( model=OpenAIChat(model="gpt-4o-mini"), tools=[ShellTool(), mcptool] )

await agent.aprint_response("Use the weather tool to check the forecast for Beijing")

```

Using Low-Level MCPClient and Server Classes

For more control, you can directly use the MCPClient and server classes:

```python import asyncio from agentica.mcp.client import MCPClient from agentica.mcp.server import MCPServerStdio, MCPServerSse

async def stdioexample(): """Example using stdio transport""" server = MCPServerStdio( name="MathTools", params={ "command": "python", "args": ["path/to/your/mcpserver.py"], "env": {"VAR": "value"} } )

async with MCPClient(server=server) as client:
    # List available tools
    tools = await client.list_tools()
    print(f"Available tools: {[tool.name for tool in tools]}")

    # Call a tool
    result = await client.call_tool("add", {"a": 5, "b": 7})
    text_result = client.extract_result_text(result)
    print(f"5 + 7 = {text_result}")

async def sseexample(): """Example using SSE transport""" server = MCPServerSse( name="WeatherService", params={ "url": "http://localhost:8081/sse", "headers": {"Authorization": "Bearer your-token"}, # Optional "timeout": 5.0, # HTTP request timeout "sseread_timeout": 300.0 # SSE connection timeout } )

async with MCPClient(server=server) as client:
    # Use client as in stdio example
    tools = await client.list_tools()
    result = await client.call_tool("get_weather", {"city": "Beijing"})
    print(client.extract_result_text(result))

if name == "main": asyncio.run(stdioexample()) asyncio.run(sseexample()) ```

McpTool Configuration Options

The McpTool class supports several configuration options:

Transport Options

You must provide one of these to specify the transport method:

  • stdio_command: Command string to run the MCP server via stdio transport
  • sse_server_url: URL of the SSE endpoint for SSE transport
  • server_params: Directly provide StdioServerParameters for stdio transport
  • session: Directly provide an initialized ClientSession

SSE Configuration

For SSE transport, you can configure:

  • sse_headers: HTTP headers for the SSE connection
  • sse_timeout: HTTP request timeout in seconds (default: 5.0)
  • sse_read_timeout: SSE connection timeout in seconds (default: 300.0)

Tool Filtering

You can filter which tools are exposed to your agent:

  • include_tools: List of tool names to include (if None, includes all)
  • exclude_tools: List of tool names to exclude

Other Options

  • env: Environment variables to pass to the server process (for stdio transport)

Example

```python

Create an McpTool with SSE transport

from agentica.tools.mcptool import McpTool mcptool = McpTool( sseserverurl="http://localhost:8081/sse", sseheaders={"Authorization": "Bearer token123"}, includetools=["getweather", "getforecast"], excludetools=["admintool"] )

Create an McpTool with stdio transport

mcptool = McpTool( stdiocommand="python weatherserver.py --port 8081", env={"APIKEY": "yourapikey"}, includetools=["getweather"] ) ```

Backward Compatibility

The McpTool class still supports environment variables for backward compatibility:

```python from agentica.tools.mcp_tool import McpTool

Using environment variables for SSE configuration

env = { "MCPSERVERURL": "http://localhost:8081/sse", "MCPSERVERHEADERS": '{"Authorization": "Bearer token123"}', "MCPSERVERTIMEOUT": "5", "MCPSERVERREAD_TIMEOUT": "300" }

mcp_tool = McpTool(env=env) ```

However, using the direct parameters is recommended for clarity and type safety.

MCP Server Implementation

If you're implementing your own MCP server, you can use the FastMCP class from the mcp package:

```python from mcp.server.fastmcp import FastMCP

Create server

mcp = FastMCP("My MCP Server", host="0.0.0.0", port=8081)

Define a tool

@mcp.tool() def get_weather(city: str) -> str: """Get weather for a city""" # Implementation here return f"Weather for {city}: Sunny, 25°C"

Run the server

if name == "main": # Use 'stdio' or 'sse' transport mcp.run(transport="sse") ```

Examples

Check out the examples directory for more complete examples:

  • examples/41_mcp_stdio_demo.py: Demonstrates how to use MCP with stdio transport
  • examples/42_mcp_sse_server.py: A simple MCP server with SSE transport
  • examples/42_mcp_sse_client.py: Demonstrates how to connect to an MCP SSE server

Full Changelog: https://github.com/shibing624/agentica/compare/0.2.3...1.0.0

- Python
Published by shibing624 about 1 year ago

agentica - 0.2.3

v0.2.3

ZhipuAI提供了免费的模型api,包括:模型:glm-4-flash, glm-4v-flash, CogView-3-Flash, CogVideoX-Flash 和工具:文档(PDF、DOC、PPT、JPG等格式)内容抽取, Web-Search-Pro 免费专区:https://bigmodel.cn/dev/activities/free/glm-4-flash

均已经兼容到agentica库。

调用示例:

https://github.com/shibing624/agentica/blob/main/examples/40websearchzhipuaidemo.py

Full Changelog: https://github.com/shibing624/agentica/compare/0.2.0...0.2.3

- Python
Published by shibing624 over 1 year ago

agentica - 0.2.0

v0.2.0 版本

  • 支持了多模态大模型;
  • 改进了workflow的逻辑;
  • 升级Assistant为Agent的处理;
  • 支持multi-agent的2种模式:team和workflow。
  • 所有的demo全部重写了。

| 示例 | 描述 | |-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| | examples/01llmdemo.py | LLM问答Demo | | examples/02userprompt_demo.py | 自定义用户prompt的Demo | | examples/03usermessages_demo.py | 自定义输入用户消息的Demo | | examples/04memorydemo.py | Agent的记忆Demo | | examples/05responsemodel_demo.py | 按指定格式(pydantic的BaseModel)回复的Demo | | examples/06calcwithcsvfile_demo.py | LLM加载CSV文件,并执行计算来回答的Demo | | examples/07createimagetooldemo.py | 实现了创建图像工具的Demo | | examples/08ocrtool_demo.py | 实现了OCR工具的Demo | | examples/09removeimagebackgroundtool_demo.py | 实现了自动去除图片背景功能,包括自动通过pip安装库,调用库实现去除图片背景 | | examples/10visiondemo.py | 视觉理解Demo | | examples/11websearchopenaidemo.py | 基于OpenAI的function call做网页搜索Demo | | examples/12websearchmoonshotdemo.py | 基于Moonshot的function call做网页搜索Demo | | examples/13storagedemo.py | Agent的存储Demo | | examples/14customtool_demo.py | 自定义工具,并用大模型自主选择调用的Demo | | examples/15crawlwebpage_demo.py | 实现了网页分析工作流:从Url爬取融资快讯 - 分析网页内容和格式 - 提取核心信息 - 汇总存为md文件 | | examples/16gettoppapersdemo.py | 解析每日论文,并保存为json格式的Demo | | examples/17findpaperfromarxiv_demo.py | 实现了论文推荐的Demo:自动从arxiv搜索多组论文 - 相似论文去重 - 提取核心论文信息 - 保存为csv文件 | | examples/18agentinputislist.py | 展示Agent的message可以是列表的Demo | | examples/19naiverag_demo.py | 实现了基础版RAG,基于Txt文档回答问题 | | examples/20advancedrag_demo.py | 实现了高级版RAG,基于PDF文档回答问题,新增功能:pdf文件解析、query改写,字面+语义多路混合召回,召回排序(rerank) | | examples/21memorydbrag_demo.py | 把参考资料放到prompt的传统RAG做法的Demo | | examples/22chatpdfappdemo.py | 对PDF文档做深入对话的Demo | | examples/23pythonagentmemorydemo.py | 实现了带记忆的Code Interpreter功能,自动生成python代码并执行,下次执行时从记忆获取结果 | | examples/24contextdemo.py | 实现了传入上下文进行对话的Demo | | examples/25toolswithcontextdemo.py | 工具带上下文传参的Demo | | examples/26complextranslate_demo.py | 实现了复杂翻译Demo | | examples/27researchagent_demo.py | 实现了Research功能,自动调用搜索工具,汇总信息后撰写科技报告 | | examples/28ragintegratedlangchaindemo.py | 集成LangChain的RAG Demo | | examples/29ragintegratedllamaindexdemo.py | 集成LlamaIndex的RAG Demo | | examples/30textclassification_demo.py | 实现了自动训练分类模型的Agent:读取训练集文件并理解格式 - 谷歌搜索pytextclassifier库 - 爬取github页面了解pytextclassifier的调用方法 - 写代码并执行fasttext模型训练 - check训练好的模型预测结果 | | examples/31teamnewsarticledemo.py | Team实现:写新闻稿的team协作,multi-role实现,委托不用角色完成各自任务:研究员检索分析文章,撰写员根据排版写文章,汇总多角色成果输出结果 | | examples/32teamdebate_demo.py | Team实现:基于委托做双人辩论Demo,特朗普和拜登辩论 | | examples/33selfevolvingagentdemo.py | 实现了自我进化Agent的Demo | | examples/34llmos_demo.py | 实现了LLM OS的初步设计,基于LLM设计操作系统,可以通过LLM调用RAG、代码执行器、Shell等工具,并协同代码解释器、研究助手、投资助手等来解决问题。 | | examples/35workflowinvestment_demo.py | 实现了投资研究的工作流:股票信息收集 - 股票分析 - 撰写分析报告 - 复查报告等多个Task | | examples/36workflownewsarticledemo.py | 实现了写新闻稿的工作流,multi-agent的实现,多次调用搜索工具,并生成高级排版的新闻文章 | | examples/37workflowwritenoveldemo.py | 实现了写小说的工作流:定小说提纲 - 搜索谷歌反思提纲 - 撰写小说内容 - 保存为md文件 | | examples/38workflowwritetutorialdemo.py | 实现了写技术教程的工作流:定教程目录 - 反思目录内容 - 撰写教程内容 - 保存为md文件 | | examples/39audiomultiturndemo.py | 基于openai的语音api做多轮音频对话的Demo |

Full Changelog: https://github.com/shibing624/agentica/compare/0.1.3...0.2.0

- Python
Published by shibing624 over 1 year ago

agentica - 0.1.0

agentica是一个Agent构建工具,功能:

  • 简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Multi-Role、Workflow等功能
  • Agent支持prompt自定义,支持多种工具调用(tool_calls)
  • 支持OpenAI/Azure/Claude/Ollama/Together API调用

实现的demo示例有:

| 示例 | 描述 | |---------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------| | examples/naiveragdemo.py | 实现了基础版RAG,基于Txt文档回答问题 | | examples/advancedragdemo.py | 实现了高级版RAG,基于PDF文档回答问题,新增功能:pdf文件解析、query改写,字面+语义多路召回,召回排序(rerank) | | examples/pythonassistantdemo.py | 实现了Code Interpreter功能,自动生成python代码,并执行 | | examples/research_demo.py | 实现了Research功能,自动调用搜索工具,汇总信息后撰写科技报告 | | examples/teamnewsarticle_demo.py | 实现了写新闻稿的team协作,multi-role实现,委托不用角色完成各自任务:研究员检索分析文章,撰写员根据排版写文章,汇总多角色成果输出结果 | | examples/workflownewsarticle_demo.py | 实现了写新闻稿的工作流,multi-agent的实现,定义了多个Assistant和Task,多次调用搜索工具,并生成高级排版的新闻文章 | | examples/workflowinvestmentdemo.py | 实现了投资研究的工作流:股票信息收集 - 股票分析 - 撰写分析报告 - 复查报告等多个Task | | examples/crawlwebpagedemo.py | 实现了网页分析工作流:从Url爬取融资快讯 - 分析网页内容和格式 - 提取核心信息 - 汇总保存为md文件 | | examples/findpaperfromarxivdemo.py | 实现了论文推荐工作流:自动从arxiv搜索多组论文 - 相似论文去重 - 提取核心论文信息 - 保存为csv文件 | | examples/removeimagebackground_demo.py | 实现了自动去除图片背景功能,包括自动通过pip安装库,调用库实现去除图片背景 | | examples/textclassificationdemo.py | 实现了自动训练分类模型的工作流:读取训练集文件并理解格式 - 谷歌搜索pytextclassifier库 - 爬取github页面了解pytextclassifier的调用方法 - 写代码并执行fasttext模型训练 - check训练好的模型预测结果 | | examples/llmosdemo.py | 实现了LLM OS的初步设计,基于LLM设计操作系统,可以通过LLM调用RAG、代码执行器、Shell等工具,并协同代码解释器、研究助手、投资助手等来解决问题。 |

Full Changelog: https://github.com/shibing624/agentica/compare/0.0.6...0.1.0

- Python
Published by shibing624 almost 2 years ago

agentica - 0.0.6

Full Changelog: https://github.com/shibing624/agentica/compare/0.0.5...0.0.6

- Python
Published by shibing624 almost 2 years ago

agentica - 0.0.5

Full Changelog: https://github.com/shibing624/actionflow/compare/0.0.4...0.0.5

- Python
Published by shibing624 almost 2 years ago

agentica - 0.0.4

What's Changed

  • Dev by @shibing624 in https://github.com/shibing624/actionflow/pull/3

New Contributors

  • @shibing624 made their first contribution in https://github.com/shibing624/actionflow/pull/3

Full Changelog: https://github.com/shibing624/actionflow/commits/0.0.4

- Python
Published by shibing624 almost 2 years ago