Skip to content

Commit 1518bf9

Browse files
committed
Update python-sdk.md
add some documentation
1 parent a5c7e9c commit 1518bf9

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

docs/python-sdk.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,136 @@ The SDK provides these tools for LLM integration:
227227
- `create_long_term_memories` (deprecated) → use `eagerly_create_long_term_memory`
228228
- `add_memory_to_working_memory` (deprecated) → use `lazily_create_long_term_memory`
229229

230+
### Customizing Tool Descriptions
231+
232+
The SDK provides `ToolSchema` and `ToolSchemaCollection` wrapper classes that allow you to customize tool descriptions, names, and parameter descriptions before passing them to LLMs. This is useful for:
233+
234+
- Adjusting descriptions to match your application's tone or domain
235+
- Renaming tools to avoid conflicts with other tools
236+
- Adding context-specific information to parameter descriptions
237+
238+
#### Basic Customization
239+
240+
```python
241+
from agent_memory_client import MemoryAPIClient
242+
243+
# Get a tool schema and customize it
244+
schema = MemoryAPIClient.get_memory_search_tool_schema()
245+
schema.set_description("Search through the user's personal knowledge base")
246+
schema.set_name("search_knowledge_base")
247+
248+
# Customize parameter descriptions
249+
schema.set_parameter_description("query", "Natural language search query")
250+
251+
# Use with LLM
252+
response = await openai_client.chat.completions.create(
253+
model="gpt-4o",
254+
messages=messages,
255+
tools=[schema.to_dict()]
256+
)
257+
```
258+
259+
#### Method Chaining
260+
261+
All setter methods return `self` for fluent method chaining:
262+
263+
```python
264+
schema = (MemoryAPIClient.get_memory_search_tool_schema()
265+
.set_description("Find relevant information from memory")
266+
.set_name("find_info")
267+
.set_parameter_description("query", "What to search for"))
268+
```
269+
270+
#### Bulk Customization with Collections
271+
272+
When working with all tools, use `ToolSchemaCollection` for bulk operations:
273+
274+
```python
275+
# Get all tools as a collection
276+
all_tools = MemoryAPIClient.get_all_memory_tool_schemas()
277+
278+
# Customize specific tools by name
279+
all_tools.set_description("search_memory", "Find relevant memories")
280+
all_tools.set_name("search_memory", "find_memories")
281+
282+
# Get a specific tool for detailed customization
283+
search_tool = all_tools.get_by_name("find_memories")
284+
if search_tool:
285+
search_tool.set_parameter_description("limit", "Max results to return")
286+
287+
# List all tool names
288+
print(all_tools.names()) # ['find_memories', 'get_or_create_working_memory', ...]
289+
290+
# Convert to list for LLM consumption
291+
response = await openai_client.chat.completions.create(
292+
model="gpt-4o",
293+
messages=messages,
294+
tools=all_tools.to_list()
295+
)
296+
```
297+
298+
#### Creating Independent Copies
299+
300+
Use `copy()` to create independent copies that won't affect the original:
301+
302+
```python
303+
# Create a copy for customization
304+
custom_schema = MemoryAPIClient.get_memory_search_tool_schema().copy()
305+
custom_schema.set_description("Custom description")
306+
307+
# Original is unchanged
308+
original = MemoryAPIClient.get_memory_search_tool_schema()
309+
assert original.get_description() != custom_schema.get_description()
310+
```
311+
312+
#### Anthropic Format
313+
314+
The same customization API works for Anthropic tool schemas:
315+
316+
```python
317+
# Anthropic format
318+
schema = MemoryAPIClient.get_memory_search_tool_schema_anthropic()
319+
schema.set_description("Custom Anthropic description")
320+
321+
# Check the format
322+
print(schema.format) # "anthropic"
323+
324+
# Use with Anthropic
325+
response = await anthropic_client.messages.create(
326+
model="claude-3-5-sonnet-20241022",
327+
messages=messages,
328+
tools=[schema.to_dict()]
329+
)
330+
```
331+
332+
#### ToolSchema API Reference
333+
334+
| Method | Description |
335+
|--------|-------------|
336+
| `set_description(text)` | Set the tool description |
337+
| `set_name(name)` | Set the tool name |
338+
| `set_parameter_description(param, text)` | Set a parameter's description |
339+
| `get_description()` | Get the current description |
340+
| `get_name()` | Get the current name |
341+
| `get_parameter_description(param)` | Get a parameter's description |
342+
| `to_dict()` | Convert to dict (returns deep copy) |
343+
| `copy()` | Create an independent copy |
344+
| `format` | Property: "openai" or "anthropic" |
345+
346+
#### ToolSchemaCollection API Reference
347+
348+
| Method | Description |
349+
|--------|-------------|
350+
| `get_by_name(name)` | Get a specific tool by name |
351+
| `set_description(name, text)` | Set description for a tool by name |
352+
| `set_name(old_name, new_name)` | Rename a tool |
353+
| `names()` | Get list of all tool names |
354+
| `to_list()` | Convert to list of dicts |
355+
| `copy()` | Create an independent copy |
356+
| `len(collection)` | Get number of tools |
357+
| `collection[index]` | Access tool by index |
358+
| `for tool in collection` | Iterate over tools |
359+
230360
## Memory Operations
231361

232362
### Creating Memories

0 commit comments

Comments
 (0)