Skip to content

LangChain tools with injected arguments are not supportedΒ #259

@rohithbojja

Description

@rohithbojja

NotImplementedError: LangChain tools with injected arguments are not supported

from typing import Dict

@create_tool('add',description="Add two numbers")
def add(a: int, b: int,state: Annotated[Dict,InjectedState],tool_call_id: Annotated[str,InjectedToolCallId]) -> Command:
    """Add two numbers"""
    print("STATE",state)
    print("TOOL CALL ID",tool_call_id)
    if tool_call_id is None:
        tool_call_id = ""
    messages = state.get("messages", []) if state else []
    tool_message = ToolMessage(name="add",content=f"The sum of {a} and {b} is {a+b}",tool_call_id=tool_call_id)
    return Command(
        update={
            'messages': messages +[tool_message]
        }
        )

add_tool = to_fastmcp(add)
mcp = FastMCP("Add",tools=[add_tool])

import asyncio
server_task = asyncio.create_task(mcp.run_async(transport="sse",port=8762))

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions