Performance: Creating tools for agents
This affects the responsiveness and efficiency of agent interactions by controlling how external tools are integrated and called during runtime.
Jump into concepts and practice - no test required
import asyncio class AsyncTool: async def run(self, input): await asyncio.sleep(0.1) # Simulates fast async response return f"Processed {input}" agent = Agent(tools=[AsyncTool()]) response = await agent.run('query')
class SlowTool: def run(self, input): import time time.sleep(2) # Simulates slow response return f"Processed {input}" agent = Agent(tools=[SlowTool()]) response = agent.run('query')
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous blocking tool call | Minimal | 0 | Blocks interaction for seconds | [X] Bad |
| Asynchronous non-blocking tool call | Minimal | 0 | Minimal delay, smooth interaction | [OK] Good |
def greet(name: str) -> str:
return f"Hello, {name}!"
from langchain.agents import Tool
greet_tool = Tool(name='greet', func=greet, description='Greets a person')
result = greet_tool.func('Alice')
print(result)def add_numbers(a, b):
return a + b
from langchain.agents import Tool
add_tool = Tool(name='add', func=add_numbers, description='Adds two numbers')
result = add_tool.func(5)
print(result)