Skip to content

Commit de4cf4b

Browse files
committed
docs: Restructure usage examples and fix architecture diagram
- Fix mermaid diagram to show correct flow: Agent uses discovery results to call execution layer - Restructure Usage Examples section into two clear approaches: 1. Direct Developer Usage - programmatic calls to intelligent_tool_finder 2. Agent Integration - autonomous agent discovery and invocation - Move agent integration content from separate section into usage examples - Improve example queries to be more natural - Clarify that discovery and execution are parallel processes controlled by the agent
1 parent 2855970 commit de4cf4b

File tree

1 file changed

+52
-23
lines changed

1 file changed

+52
-23
lines changed

docs/dynamic-tool-discovery.md

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,24 @@ The dynamic tool discovery process follows these steps:
4444
graph TB
4545
subgraph "Agent Layer"
4646
A[AI Agent] --> B[Natural Language Query]
47+
A --> H[invoke_mcp_tool]
4748
end
4849
4950
subgraph "Discovery Layer"
5051
B --> C[intelligent_tool_finder]
5152
C --> D[Sentence Transformer]
5253
C --> E[FAISS Index]
53-
end
54-
55-
subgraph "Registry Layer"
5654
E --> F[Tool Metadata]
5755
F --> G[Server Information]
56+
G --> K[Tool Discovery Results]
57+
K --> A
5858
end
5959
6060
subgraph "Execution Layer"
61-
G --> H[invoke_mcp_tool]
6261
H --> I[Target MCP Server]
62+
I --> J[Tool Result]
63+
J --> A
6364
end
64-
65-
I --> J[Tool Result]
66-
J --> A
6765
```
6866

6967
### Key Technologies
@@ -75,33 +73,60 @@ graph TB
7573

7674
## Usage Examples
7775

78-
### Basic Tool Discovery
76+
Dynamic tool discovery can be used in two primary ways:
77+
78+
### 1. Direct Developer Usage
79+
80+
Agent developers can directly call the `intelligent_tool_finder` in their code to discover tools, then use the results with the `invoke_mcp_tool` function to call the discovered tool.
81+
82+
#### Basic Discovery
7983

8084
```python
81-
# Agent discovers time-related tools
82-
result = intelligent_tool_finder("current time in different timezone")
85+
# Basic usage with session cookie
86+
tools = await intelligent_tool_finder(
87+
natural_language_query="what time is it in Tokyo",
88+
session_cookie="your_session_cookie_here"
89+
)
8390

8491
# Returns information about relevant tools:
85-
# {
86-
# "tool_name": "current_time_by_timezone",
87-
# "service_path": "/currenttime",
88-
# "service_name": "Current Time Server",
89-
# "tool_schema": {...},
90-
# "overall_similarity_score": 0.89
91-
# }
92+
# [
93+
# {
94+
# "tool_name": "current_time_by_timezone",
95+
# "service_path": "/currenttime",
96+
# "service_name": "Current Time Server",
97+
# "tool_schema": {...},
98+
# "overall_similarity_score": 0.89
99+
# }
100+
# ]
101+
```
102+
103+
#### Advanced Discovery
104+
105+
```python
106+
# Advanced usage with multiple results
107+
tools = await intelligent_tool_finder(
108+
natural_language_query="stock market information and financial data",
109+
username="admin",
110+
password="your_password",
111+
top_k_services=5,
112+
top_n_tools=3
113+
)
92114
```
93115

94-
### Complete Workflow Example
116+
#### Complete Workflow
95117

96118
```python
97119
# 1. Discover tools for weather information
98-
weather_tools = intelligent_tool_finder("weather forecast for tomorrow")
120+
weather_tools = await intelligent_tool_finder(
121+
natural_language_query="weather forecast for tomorrow",
122+
session_cookie="your_session_cookie"
123+
)
99124

100125
# 2. Use the discovered tool
101126
if weather_tools:
102127
tool_info = weather_tools[0] # Get the best match
103128

104-
result = invoke_mcp_tool(
129+
result = await invoke_mcp_tool(
105130
mcp_registry_url="https://your-registry.com/mcpgw/sse",
106131
server_name=tool_info["service_path"], # e.g., "/weather"
107132
tool_name=tool_info["tool_name"], # e.g., "get_forecast"
@@ -114,9 +139,11 @@ if weather_tools:
114139
)
115140
```
116141

117-
## Agent Integration
142+
### 2. Agent Integration
143+
144+
The more powerful approach is when AI agents themselves use dynamic tool discovery autonomously. The agent has access to both `intelligent_tool_finder` and `invoke_mcp_tool` as available tools, allowing it to discover and execute new capabilities on-demand.
118145

119-
### System Prompt Configuration
146+
#### System Prompt Configuration
120147

121148
Agents are configured with instructions on how to use dynamic tool discovery:
122149

@@ -138,7 +165,7 @@ Example workflow:
138165
</tool_discovery>
139166
```
140167

141-
### Agent Implementation
168+
#### Agent Implementation
142169

143170
The agent implementation in [`agents/agent.py`](../agents/agent.py) shows how to:
144171

@@ -163,6 +190,8 @@ logger.info(f"All available tools: {[tool.name if hasattr(tool, 'name') else too
163190
agent = create_react_agent(model, all_tools)
164191
```
165192

193+
This integration enables agents to have **limitless capabilities** - they can handle any task for which there's an appropriate MCP tool registered in the system, even if they weren't originally programmed with knowledge of that tool.
194+
166195
## API Reference
167196

168197
### intelligent_tool_finder

0 commit comments

Comments
 (0)