Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions TOOLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The Flo AI tools system allows you to create and configure tools that can be use
- **Entity-attached tools**: Tools that require specific context or configuration (e.g., BigQuery with datasource ID, email with SMTP settings)

The system supports:

- Basic tool creation and usage
- Partial tools with pre-filled parameters
- YAML-based tool configuration
Expand Down Expand Up @@ -55,6 +56,7 @@ async def calculate(expression: str, precision: int = 2) -> str:
### Tool Properties

Every tool has these properties:

- `name`: Tool name (defaults to function name)
- `description`: Tool description (defaults to docstring)
- `parameters`: Dictionary of parameter definitions
Expand All @@ -81,6 +83,7 @@ Partial tools allow you to pre-fill some parameters during agent building, hidin
### Why Use Partial Tools?

**Problem**: Some tools require context-specific parameters that shouldn't be provided by the AI:

- BigQuery tools need `datasource_id` and `project_id`
- Email tools need SMTP server configuration
- Database tools need connection strings
Expand Down Expand Up @@ -130,7 +133,7 @@ agent = (AgentBuilder()
.with_tools([
{
"tool": bigquery_query.tool,
"pre_filled_params": {
"prefilled_params": {
"datasource_id": "ds_production_123",
"project_id": "my-company-prod",
"dataset": "analytics"
Expand Down Expand Up @@ -194,7 +197,7 @@ from flo_ai.tool.tool_config import ToolConfig

tool_config = ToolConfig(
tool=my_tool,
pre_filled_params={"param1": "value1", "param2": "value2"},
prefilled_params={"param1": "value1", "param2": "value2"},
name_override="custom_tool_name",
description_override="Custom tool description"
)
Expand All @@ -207,7 +210,7 @@ configured_tool = tool_config.to_tool()

- `is_partial()`: Check if the tool has pre-filled parameters
- `to_tool()`: Convert configuration to a Tool object
- `get_pre_filled_params()`: Get pre-filled parameters
- `get_prefilled_params()`: Get pre-filled parameters

## YAML Configuration

Expand All @@ -225,19 +228,19 @@ agent:
tools:
# Simple tool reference
- "calculate"

# Tool with pre-filled parameters
- name: "bigquery_query"
pre_filled_params:
prefilled_params:
datasource_id: "ds_production_123"
project_id: "my-company-prod"
dataset: "analytics"
name_override: "query_production_data"
description_override: "Query production BigQuery data"

# Tool with different configuration
- name: "web_search"
pre_filled_params:
prefilled_params:
max_results: 5
language: "en"
name_override: "search_web"
Expand All @@ -257,15 +260,15 @@ agent:
name: "gpt-4"
tools:
- name: "bigquery_query"
pre_filled_params:
prefilled_params:
datasource_id: "ds_production_123"
project_id: "my-company-prod"
dataset: "analytics"
name_override: "query_production_data"
description_override: "Query production BigQuery data"

- name: "send_email"
pre_filled_params:
prefilled_params:
smtp_server: "smtp.company.com"
smtp_port: 587
name_override: "send_notification"
Expand All @@ -283,15 +286,15 @@ agent:
name: "gpt-4"
tools:
- name: "bigquery_query"
pre_filled_params:
prefilled_params:
datasource_id: "ds_dev_456"
project_id: "my-company-dev"
dataset: "test_data"
name_override: "query_dev_data"
description_override: "Query development BigQuery data"

- name: "web_search"
pre_filled_params:
prefilled_params:
max_results: 3
language: "en"
name_override: "search_web"
Expand Down Expand Up @@ -394,14 +397,14 @@ agent:
tools:
- "calculate"
- name: "bigquery_query"
pre_filled_params:
prefilled_params:
datasource_id: "ds_production_123"
project_id: "my-company-prod"
dataset: "analytics"
name_override: "query_production_data"
description_override: "Query production BigQuery data"
- name: "web_search"
pre_filled_params:
prefilled_params:
max_results: 5
language: "en"
name_override: "search_web"
Expand Down Expand Up @@ -442,6 +445,7 @@ agent = AgentBuilder.from_yaml(
```

**Parameters:**

- `name`: Custom name for the tool (defaults to function name)
- `description`: Tool description (defaults to function docstring)
- `parameter_descriptions`: Dict mapping parameter names to descriptions
Expand All @@ -453,16 +457,17 @@ class ToolConfig:
def __init__(
self,
tool: Tool,
pre_filled_params: Optional[Dict[str, Any]] = None,
prefilled_params: Optional[Dict[str, Any]] = None,
name_override: Optional[str] = None,
description_override: Optional[str] = None,
)
```

**Methods:**

- `is_partial() -> bool`: Check if tool has pre-filled parameters
- `to_tool() -> Tool`: Convert to Tool object
- `get_pre_filled_params() -> Dict[str, Any]`: Get pre-filled parameters
- `get_prefilled_params() -> Dict[str, Any]`: Get pre-filled parameters

### PartialTool Class

Expand All @@ -471,23 +476,24 @@ class PartialTool(Tool):
def __init__(
self,
base_tool: Tool,
pre_filled_params: Dict[str, Any],
prefilled_params: Dict[str, Any],
name_override: Optional[str] = None,
description_override: Optional[str] = None,
)
```

**Methods:**

- `get_original_tool() -> Tool`: Get the original tool
- `get_pre_filled_params() -> Dict[str, Any]`: Get pre-filled parameters
- `add_pre_filled_param(key: str, value: Any) -> PartialTool`: Add parameter
- `remove_pre_filled_param(key: str) -> PartialTool`: Remove parameter
- `get_prefilled_params() -> Dict[str, Any]`: Get pre-filled parameters
- `add_prefilled_param(key: str, value: Any) -> PartialTool`: Add parameter
- `remove_prefilled_param(key: str) -> PartialTool`: Remove parameter

### AgentBuilder Methods

```python
# Add single tool with optional pre-filled parameters
def add_tool(self, tool: Tool, **pre_filled_params) -> 'AgentBuilder'
def add_tool(self, tool: Tool, **prefilled_params) -> 'AgentBuilder'

# Add multiple tools (supports Tool, ToolConfig, or dict)
def with_tools(self, tools: Union[List[Tool], List[ToolConfig], List[Dict[str, Any]]]) -> 'AgentBuilder'
Expand Down Expand Up @@ -551,7 +557,7 @@ def test_tool_execution():
function=mock_function,
parameters={"param1": {"type": "string", "description": "Param 1", "required": True}}
)

result = await tool.execute(param1="test_value")
assert result == "test_result"
mock_function.assert_called_once_with(param1="test_value")
Expand All @@ -569,7 +575,7 @@ def test_tool_execution():
### Debug Tips

1. **Check tool parameters**: Use `tool.parameters` to see what the AI sees
2. **Verify pre-filled params**: Use `partial_tool.get_pre_filled_params()`
2. **Verify pre-filled params**: Use `partial_tool.get_prefilled_params()`
3. **Test tool execution**: Test tools independently before using in agents
4. **Check YAML structure**: Validate YAML with online validators

Expand Down
14 changes: 7 additions & 7 deletions flo_ai/examples/partial_tool_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def main():
# Tool with pre-filled parameters using dictionary format
{
'tool': bigquery_query.tool,
'pre_filled_params': {
'prefilled_params': {
'datasource_id': 'ds_production_456',
'project_id': 'company-prod',
'dataset': 'analytics',
Expand All @@ -128,7 +128,7 @@ async def main():
# Tool with pre-filled parameters using dictionary format
{
'tool': web_search.tool,
'pre_filled_params': {'max_results': 3, 'language': 'en'},
'prefilled_params': {'max_results': 3, 'language': 'en'},
},
# Regular tool without pre-filling
calculate.tool,
Expand Down Expand Up @@ -171,12 +171,12 @@ async def main():
print('5. Demonstrating parameter management...')

# Add a new pre-filled parameter
bigquery_partial.add_pre_filled_param('timeout', 30)
print(f'Added timeout parameter: {bigquery_partial.get_pre_filled_params()}')
bigquery_partial.add_prefilled_param('timeout', 30)
print(f'Added timeout parameter: {bigquery_partial.get_prefilled_params()}')

# Remove a parameter
bigquery_partial.remove_pre_filled_param('timeout')
print(f'Removed timeout parameter: {bigquery_partial.get_pre_filled_params()}')
bigquery_partial.remove_prefilled_param('timeout')
print(f'Removed timeout parameter: {bigquery_partial.get_prefilled_params()}')
print()

# Show the difference between original and partial tools
Expand All @@ -191,7 +191,7 @@ async def main():
print(f" - {param}: {info['type']} (required: {info['required']})")

print(
f'\nPre-filled parameters (hidden from AI): {bigquery_partial.get_pre_filled_params()}'
f'\nPre-filled parameters (hidden from AI): {bigquery_partial.get_prefilled_params()}'
)


Expand Down
18 changes: 9 additions & 9 deletions flo_ai/examples/tools_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ async def main():
print(f" - {param}: {info['type']} (required: {info['required']})")

# Show pre-filled parameters
if hasattr(partial_tool, 'get_pre_filled_params'):
if hasattr(partial_tool, 'get_prefilled_params'):
print(
f'\nPre-filled parameters (hidden from AI): {partial_tool.get_pre_filled_params()}'
f'\nPre-filled parameters (hidden from AI): {partial_tool.get_prefilled_params()}'
)
print()

Expand Down Expand Up @@ -157,14 +157,14 @@ async def main():
tools:
- "calculate"
- name: "query_database"
pre_filled_params:
prefilled_params:
database_url: "postgresql://yaml-db.company.com:5432/data"
timeout: 45
max_rows: 2000
name_override: "query_yaml_database"
description_override: "Query YAML-configured database"
- name: "web_search"
pre_filled_params:
prefilled_params:
max_results: 3
language: "en"
name_override: "search_web"
Expand All @@ -189,14 +189,14 @@ async def main():
# 7. Tool parameter management
print('7. Tool parameter management...')

if hasattr(partial_tool, 'add_pre_filled_param'):
if hasattr(partial_tool, 'add_prefilled_param'):
# Add a new pre-filled parameter
partial_tool.add_pre_filled_param('retry_count', 3)
print(f'Added retry_count parameter: {partial_tool.get_pre_filled_params()}')
partial_tool.add_prefilled_param('retry_count', 3)
print(f'Added retry_count parameter: {partial_tool.get_prefilled_params()}')

# Remove a parameter
partial_tool.remove_pre_filled_param('retry_count')
print(f'Removed retry_count parameter: {partial_tool.get_pre_filled_params()}')
partial_tool.remove_prefilled_param('retry_count')
print(f'Removed retry_count parameter: {partial_tool.get_prefilled_params()}')
print()

print('=== Quick Start Complete ===')
Expand Down
18 changes: 9 additions & 9 deletions flo_ai/examples/yaml_tool_config_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ async def main():
name: "gpt-4"
tools:
- name: "bigquery_query"
pre_filled_params:
prefilled_params:
datasource_id: "ds_production_123"
project_id: "my-company-prod"
dataset: "analytics"
name_override: "query_production_data"
description_override: "Query production BigQuery data"

- name: "web_search"
pre_filled_params:
prefilled_params:
max_results: 5
language: "en"
name_override: "search_web"
description_override: "Search the web for information"

- name: "send_email"
pre_filled_params:
prefilled_params:
smtp_server: "smtp.company.com"
smtp_port: 587
name_override: "send_notification"
Expand Down Expand Up @@ -160,15 +160,15 @@ async def main():
name: "gpt-4"
tools:
- name: "bigquery_query"
pre_filled_params:
prefilled_params:
datasource_id: "ds_dev_456"
project_id: "my-company-dev"
dataset: "test_data"
name_override: "query_dev_data"
description_override: "Query development BigQuery data"

- name: "web_search"
pre_filled_params:
prefilled_params:
max_results: 3
language: "en"
name_override: "search_web"
Expand Down Expand Up @@ -198,13 +198,13 @@ async def main():
- "calculate" # Simple reference

- name: "bigquery_query"
pre_filled_params:
prefilled_params:
datasource_id: "ds_mixed_789"
project_id: "mixed-project"
dataset: "mixed_data"

- name: "web_search"
pre_filled_params:
prefilled_params:
max_results: 10
language: "en"
name_override: "search_web"
Expand Down Expand Up @@ -238,7 +238,7 @@ async def main():

tool_config = ToolConfig(
tool=configured_tool,
pre_filled_params={
prefilled_params={
'datasource_id': 'ds_production_123',
'project_id': 'my-company-prod',
'dataset': 'analytics',
Expand All @@ -249,7 +249,7 @@ async def main():
for param, info in configured_tool_for_ai.parameters.items():
print(f" - {param}: {info['type']} (required: {info['required']})")

print(f'\nPre-filled parameters (hidden from AI): {tool_config.pre_filled_params}')
print(f'\nPre-filled parameters (hidden from AI): {tool_config.prefilled_params}')


if __name__ == '__main__':
Expand Down
Loading
Loading