Skip to content

feat: add tool support for the agent#105

Merged
blkdmr merged 1 commit into
pyfenn:mainfrom
DagaBhai:tools
May 22, 2026
Merged

feat: add tool support for the agent#105
blkdmr merged 1 commit into
pyfenn:mainfrom
DagaBhai:tools

Conversation

@DagaBhai
Copy link
Copy Markdown
Contributor

What does this PR do?

contributing to #104

adds a tool support for agent

files change:
tools.py - tool decorator for registering tool with the agent
node.py/ActNode - added actual executable tool calling as well as if any error happens agent will get to know
agent.py - shared dict added "tools": get_tool_schema() for the agent to know more about function and its input

Test

from fenn.agents.tools import tool, get_tool_schema, execute_tool
from fenn.agents.node import ActNode

@tool
def calculate_calculator(expression: str) -> str:
    """
    Evaluates a mathematical expression string safely.
    Use this when you need to do basic math like addition, multiplication, or division.
    """
    try:
        # Note: In production, use a safer eval alternative like simpleeval
        return str(eval(expression, {"__builtins__": None}, {}))
    except Exception as e:
        return f"Error evaluating expression: {str(e)}"

@tool
def fetch_weather(location: str, date:str) -> str:
    """
    Retrieves the current weather for a specific city location.
    """
    # Simulate a real API call or database lookup
    return f"The weather in {location} on {date} is sunny and 22°C."


print("Available tools for the LLM:")
print(get_tool_schema())

# 2. When the agent outputs a tool call, execute it
tool_call = "fetch_weather(xyz, 20-05-2026)"
thought = """
Think: I should check weather
Action: fetch_weather(xyz, 20-05-2026)
"""

result1 = ActNode.exec(ActNode(),thought=tool_call)
result2 = ActNode.exec(ActNode(),thought=thought)
print(f"\nExecution Result1: {result1}")
print(f"\nExecution Result2: {result2}")

Note

  • tool calling can only be enforced if agent has correct observation of the envirnoment, output/result will let it know if the error has happened or not to do that llm must give json or any structured output
  • If an error occurs, the error message should be passed back to the agent, as the LLM tends to provide a better fix once it knows what went wrong.

@blkdmr blkdmr merged commit 05fe124 into pyfenn:main May 22, 2026
0 of 2 checks passed
@blkdmr
Copy link
Copy Markdown
Collaborator

blkdmr commented May 22, 2026

Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants