Skip to content

Commit 2e162e8

Browse files
authored
doc(langchain-sdk): Improve doc and tests for LangChain SDK. (#154)
1 parent d5ade14 commit 2e162e8

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ access tokens for [Google OAuth
195195

196196
### Configuring Tools for Authentication
197197

198-
Refer to [these instructions](https://github.com/googleapis/genai-toolbox/blob/main/docs/tools/README.md#authenticated-parameters) on configuring tools for authenticated parameters.
198+
Refer to [these
199+
instructions](../../docs/tools/README.md#authenticated-parameters) on
200+
configuring tools for authenticated parameters.
199201

200202
### Configure SDK for Authentication
201203

@@ -230,11 +232,9 @@ toolbox.add_auth_header("my_auth_service", get_auth_header)
230232
```
231233

232234
> [!NOTE]
233-
> After adding authentication headers, either through `load_tool`,
234-
> `load_toolset`, or `add_auth_header`, all subsequent tool invocations from
235-
> that point onward will use these authentications, regardless of whether the
236-
> tool was loaded before or after calling these methods. This maintains a
237-
> consistent authentication context.
235+
> Authentication headers added via `load_tool`, `load_toolset`, or
236+
> `add_auth_header` apply to all subsequent tool invocations, regardless of when
237+
> the tool was loaded. This ensures a consistent authentication context.
238238
239239
### Complete Example
240240

src/toolbox_langchain_sdk/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ def _get_auth_headers(id_token_getters: dict[str, Callable[[], str]]) -> dict[st
106106
headers to be included in tool invocation.
107107
108108
Args:
109-
id_token_getters: A dict that maps auth source names to the functions
110-
that return its ID token.
109+
id_token_getters: A dict that maps auth source names to the functions
110+
that return its ID token.
111111
112112
Returns:
113-
A dictionary of headers to be included in the tool invocation.
113+
A dictionary of headers to be included in the tool invocation.
114114
"""
115115
auth_headers = {}
116116
for auth_source, get_id_token in id_token_getters.items():

tests/test_client.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,17 @@ async def test_generate_tool_success():
135135
assert isinstance(tool, StructuredTool)
136136
assert tool.name == "test_tool"
137137
assert tool.description == "This is test tool."
138-
assert tool.args_schema is not None # Check if args_schema is generated
138+
assert tool.args is not None
139+
140+
assert "param1" in tool.args
141+
assert tool.args["param1"]["title"] == "Param1"
142+
assert tool.args["param1"]["description"] == "Parameter 1"
143+
assert tool.args["param1"]["anyOf"] == [{"type": "string"}, {"type": "null"}]
144+
145+
assert "param2" in tool.args
146+
assert tool.args["param2"]["title"] == "Param2"
147+
assert tool.args["param2"]["description"] == "Parameter 2"
148+
assert tool.args["param2"]["anyOf"] == [{"type": "integer"}, {"type": "null"}]
139149

140150

141151
@pytest.mark.asyncio
@@ -258,7 +268,7 @@ async def test_generate_tool_invoke(mock_invoke_tool):
258268
tool = client._generate_tool("test_tool", ManifestSchema(**manifest_data))
259269

260270
# Call the tool function with some arguments
261-
result = await tool.coroutine(param1="test_value", param2=123)
271+
result = await tool.ainvoke({"param1": "test_value", "param2": 123})
262272

263273
# Assert that _invoke_tool was called with the correct parameters
264274
mock_invoke_tool.assert_called_once_with(
@@ -739,7 +749,10 @@ async def test_generate_tool(
739749
assert isinstance(tool, StructuredTool)
740750
assert tool.name == "tool_name"
741751
assert tool.description == "Test tool description"
742-
assert tool.args_schema.__name__ == "tool_name"
752+
assert "param1" in tool.args
753+
assert tool.args["param1"]["title"] == "Param1"
754+
assert tool.args["param1"]["description"] == "Test param"
755+
assert tool.args["param1"]["anyOf"] == [{"type": "string"}, {"type": "null"}]
743756

744757
# Call the tool function to check if _invoke_tool is called
745758
if expected_invoke_tool_call:

0 commit comments

Comments
 (0)