Skip to content

Commit d102250

Browse files
authored
Fix bug where generics causes tools to roundtrip and loose properties. (#195)
1 parent 59410d7 commit d102250

6 files changed

Lines changed: 27 additions & 3 deletions

File tree

dreadnode/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
if t.TYPE_CHECKING:
3939
from dreadnode import agent, airt, eval, optimization, scorers, transforms # noqa: A004
40+
from dreadnode.agent import Agent, tool, tool_method
4041
from dreadnode.data_types import Audio, Image, Table, Video
4142

4243
logger.disable("dreadnode")
@@ -75,6 +76,7 @@
7576

7677
__all__ = [
7778
"DEFAULT_INSTANCE",
79+
"Agent",
7880
"Audio",
7981
"Code",
8082
"Config",
@@ -138,6 +140,8 @@
138140
"task",
139141
"task_and_run",
140142
"task_span",
143+
"tool",
144+
"tool_method",
141145
"transforms",
142146
]
143147

@@ -147,6 +151,9 @@
147151
"Image": "dreadnode.data_types",
148152
"Table": "dreadnode.data_types",
149153
"Video": "dreadnode.data_types",
154+
"Agent": "dreadnode.agent",
155+
"tool": "dreadnode.agent",
156+
"tool_method": "dreadnode.agent",
150157
}
151158

152159

dreadnode/agent/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dreadnode.agent.agent import Agent
55
from dreadnode.agent.result import AgentResult
66
from dreadnode.agent.thread import Thread
7+
from dreadnode.agent.tools import tool, tool_method
78

89
Agent.model_rebuild()
910
Thread.model_rebuild()
@@ -20,5 +21,7 @@
2021
"reactions",
2122
"result",
2223
"stop",
24+
"tool",
25+
"tool_method",
2326
"tools",
2427
]

dreadnode/agent/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from copy import deepcopy
55

66
import rigging as rg
7-
from pydantic import ConfigDict, Field, PrivateAttr, field_validator
7+
from pydantic import ConfigDict, Field, PrivateAttr, SkipValidation, field_validator
88
from rigging.message import inject_system_content # can't access via rg
99

1010
from dreadnode.agent.error import MaxStepsError
@@ -83,7 +83,7 @@ class Agent(Model):
8383
caching: rg.caching.CacheMode | None = Config(default=None, repr=False)
8484
"""How to handle cache_control entries on inference messages."""
8585

86-
tools: list[AnyTool | Toolset] = Config(default_factory=list)
86+
tools: t.Annotated[list[AnyTool | Toolset], SkipValidation] = Config(default_factory=list)
8787
"""Tools the agent can use."""
8888
tool_mode: ToolMode = Config(default="auto", repr=False)
8989
"""The tool calling mode to use."""

dreadnode/agent/tools/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
from dreadnode.agent.tools.base import (
55
AnyTool,
6+
FunctionCall,
7+
FunctionDefinition,
68
Tool,
9+
ToolCall,
10+
ToolDefinition,
11+
ToolMode,
712
Toolset,
813
discover_tools_on_obj,
914
tool,
@@ -15,7 +20,12 @@
1520

1621
__all__ = [
1722
"AnyTool",
23+
"FunctionCall",
24+
"FunctionDefinition",
1825
"Tool",
26+
"ToolCall",
27+
"ToolDefinition",
28+
"ToolMode",
1929
"Toolset",
2030
"discover_tools_on_obj",
2131
"fs",

dreadnode/agent/tools/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
Tool = tools.Tool
1010
ToolMode = tools.ToolMode
11+
ToolCall = tools.ToolCall
12+
FunctionCall = tools.FunctionCall
13+
ToolDefinition = tools.ToolDefinition
14+
FunctionDefinition = tools.FunctionDefinition
1115

1216
AnyTool = Tool[t.Any, t.Any]
1317

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)