@tool

Overview

The @tool decorator creates a span for a tool operation — a discrete callable used by agents (search, calculator, API call, file read). Tool spans inherit the current entity path and appear nested under the nearest agent, workflow, or task.

1from respan import tool

Parameters

ParameterTypeDefaultDescription
namestr | NoneFunction nameDisplay name for the tool span.
versionint | NoneNoneVersion number for the tool.
method_namestr | NoneNoneRequired when decorating a class. Specifies which method to use as the entry point.
processorsstr | List[str] | NoneNoneRoute this span to specific named processors. See add_processor.
export_filterFilterParamDict | NoneNoneFilter dict to control which spans are exported. Uses AND logic — all conditions must match.

Function usage

1from respan import Respan, workflow, task, tool
2
3respan = Respan(api_key="your-api-key")
4
5@tool(name="web_search")
6def web_search(query: str):
7 return f"Search results for: {query}"
8
9@tool(name="calculator")
10def calculator(expression: str):
11 return eval(expression)
12
13@task(name="research")
14def research(topic: str):
15 return web_search(topic)
16
17@workflow(name="research_workflow")
18def research_workflow():
19 data = research("Python tracing")
20 count = calculator("2 + 3")
21 return {"data": data, "count": count}
22
23print(research_workflow())

Class usage

1from respan import Respan, agent, tool
2
3respan = Respan(api_key="your-api-key")
4
5@agent(name="analysis", method_name="run")
6class Analyzer:
7 @tool(name="tokenize")
8 def tokenize(self, text: str):
9 return text.split()
10
11 @tool(name="count_words")
12 def count_words(self, text: str):
13 return len(text.split())
14
15 def run(self):
16 tokens = self.tokenize("respan tracing sdk")
17 count = self.count_words("respan tracing sdk")
18 return {"tokens": tokens, "count": count}
19
20print(Analyzer().run())

Notes

  • Tool spans automatically capture function arguments as input and return values as output
  • Exceptions inside tools are recorded on the span with error status
  • Use @tool for operations that agents call, and @task for broader processing steps