Skip to content

Commit 767333b

Browse files
committed
fixup! feat(tools): implement extended tool definitions with native PydanticAI integration
1 parent c5dae1e commit 767333b

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/agentpool/agents/native_agent/tool_wrapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async def wrapped( # pyright: ignore[reportRedeclaration]
150150
if result == "allow":
151151
# Populate AgentContext with RunContext data if needed
152152
if agent_ctx.data is None:
153-
agent_ctx.data = ctx.deps
153+
agent_ctx.data = ctx.deps.data if ctx.deps else ctx.deps
154154

155155
if agent_ctx_key: # inject AgentContext
156156
# Build model_name from RunContext's model (provider:model_name format)

src/agentpool/tools/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,18 @@ def _get_json_schema(self, func: Callable[..., Any] | None = None) -> dict[str,
245245
# Return only the parameters part (the "object" schema)
246246
# Use model_dump - schemez.FunctionSchema has this method (pydantic-compatible)
247247
schema_dump = getattr(schema, "model_dump")() # noqa: B009, type: ignore[attr-defined]
248-
return schema_dump["parameters"] # type: ignore[no-any-return]
248+
generated_params = schema_dump["parameters"]
249+
250+
# Apply parameter overrides to maintain consistency with the primary path
251+
if "parameters" in self.schema_override:
252+
override_params = self.schema_override["parameters"]
253+
if "properties" in override_params:
254+
for param_name, param_def in override_params["properties"].items():
255+
if param_name in generated_params.get("properties", {}):
256+
generated_params["properties"][param_name].update(param_def)
257+
else:
258+
generated_params.setdefault("properties", {})[param_name] = param_def
259+
return generated_params # type: ignore[no-any-return]
249260
else:
250261
return schema.json_schema
251262

tests/tools/test_runcontext.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ async def data_with_run_ctx(ctx: RunContext[AgentContext[dict[str, str]]]) -> st
2727

2828
async def data_with_agent_ctx(ctx: AgentContext) -> str:
2929
"""Tool accessing data through AgentContext."""
30-
# When a tool requests AgentContext, it gets RunContext.deps
31-
# RunContext.deps is AgentContext, and the user data is in AgentContext.data
32-
# But ctx here is AgentContext, so ctx.data contains the user data directly
33-
data_value = ctx.data.data if isinstance(ctx.data, AgentContext) else ctx.data
34-
return f"Data from AgentContext: {data_value}"
30+
return f"Data from AgentContext: {ctx.data}"
3531

3632

3733
async def no_ctx_tool() -> str:

0 commit comments

Comments
 (0)