MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / lookup_tool

Function lookup_tool

tests/lib/tools/test_runner_eager_tools.py:999–1026  ·  view source on GitHub ↗

A `lookup` tool that writes to `timeline` when it starts, and returns `value of ` unless `lookup` says otherwise.

(
    sync: bool, timeline: list[str], *, lookup: Callable[[str], str] | None = None, log_returns: bool = False
)

Source from the content-addressed store, hash-verified

997
998
999def lookup_tool(
1000 sync: bool, timeline: list[str], *, lookup: Callable[[str], str] | None = None, log_returns: bool = False
1001) -> Any:
1002 """A `lookup` tool that writes to `timeline` when it starts, and returns `value of <key>` unless `lookup` says
1003 otherwise."""
1004
1005 def run(key: str) -> str:
1006 timeline.append(f"lookup({key}) STARTS")
1007 value = f"value of {key}" if lookup is None else lookup(key)
1008 if log_returns:
1009 timeline.append(f"lookup({key}) returns")
1010 return value
1011
1012 if sync:
1013
1014 @beta_tool(name="lookup")
1015 def sync_lookup(key: str) -> str:
1016 """Look up a key."""
1017 return run(key)
1018
1019 return sync_lookup
1020
1021 @beta_async_tool(name="lookup")
1022 async def async_lookup(key: str) -> str:
1023 """Look up a key."""
1024 return run(key)
1025
1026 return async_lookup
1027
1028
1029class TimelineDesktop(Desktop):

Calls

no outgoing calls

Tested by

no test coverage detected