Skip to content

Commit 91a7b61

Browse files
committed
Merge branch 'main' of github.com:PsiACE/bub
2 parents 6d87953 + 5ec9595 commit 91a7b61

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/bub/tools/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ async def execute(
204204
if descriptor is None:
205205
raise KeyError(name)
206206

207-
if descriptor.tool.context:
208-
kwargs["context"] = context
207+
if "context" in kwargs:
208+
raise ValueError("Do not pass 'context' in kwargs; use the 'context=' argument to ToolRegistry.execute().")
209209
result = descriptor.tool.run(context=context, **kwargs)
210210
if inspect.isawaitable(result):
211211
result = await result

tests/test_tool_registry.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ def handle(*, context: ToolContext, path: str) -> str:
5151
assert logs.count("tool.call.end name={} duration={:.3f}ms") == 1
5252

5353

54+
@pytest.mark.asyncio
55+
async def test_registry_execute_context_tool_should_work() -> None:
56+
registry = ToolRegistry()
57+
58+
@registry.register(name="ctx.echo", short_description="echo", detail="echo", context=True)
59+
def echo(*, context: ToolContext, value: str) -> str:
60+
return f"{context.run_id}:{value}"
61+
62+
ctx = ToolContext(tape="t1", run_id="r1")
63+
out = await registry.execute("ctx.echo", kwargs={"value": "hi"}, context=ctx)
64+
assert out == "r1:hi"
65+
66+
5467
@pytest.mark.asyncio
5568
async def test_registry_model_tools_use_underscore_names_and_keep_handlers() -> None:
5669
registry = ToolRegistry()

0 commit comments

Comments
 (0)