mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-08 08:11:07 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cccd75ca75 | ||
|
|
395f8fb5ef | ||
|
|
e4893ad948 | ||
|
|
e717b625d2 | ||
|
|
84638ad759 | ||
|
|
626bc963f7 |
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
FROM python:3.11-slim
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN pip install flask praisonai==2.0.25 gunicorn markdown
|
||||
RUN pip install flask praisonai==2.0.27 gunicorn markdown
|
||||
EXPOSE 8080
|
||||
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
|
||||
@@ -110,7 +110,7 @@ Loads environment variables from .env file or system and sets them.</p>
|
||||
file.write("FROM python:3.11-slim\n")
|
||||
file.write("WORKDIR /app\n")
|
||||
file.write("COPY . .\n")
|
||||
file.write("RUN pip install flask praisonai==2.0.25 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==2.0.27 gunicorn markdown\n")
|
||||
file.write("EXPOSE 8080\n")
|
||||
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ class Praisonai < Formula
|
||||
|
||||
desc "AI tools for various AI applications"
|
||||
homepage "https://github.com/MervinPraison/PraisonAI"
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.25.tar.gz"
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.27.tar.gz"
|
||||
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
|
||||
license "MIT"
|
||||
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class CloudDeployer:
|
||||
file.write("FROM python:3.11-slim\n")
|
||||
file.write("WORKDIR /app\n")
|
||||
file.write("COPY . .\n")
|
||||
file.write("RUN pip install flask praisonai==2.0.25 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==2.0.27 gunicorn markdown\n")
|
||||
file.write("EXPOSE 8080\n")
|
||||
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
||||
|
||||
|
||||
+631
-488
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,133 @@
|
||||
# Understanding Tool Integration in AI Agents - A Beginner's Guide
|
||||
|
||||
## Overview
|
||||
This guide explains how to properly integrate tools (functions) that an AI agent can use, making them both understandable to the OpenAI API and executable by your code.
|
||||
|
||||
## Key Components
|
||||
|
||||
### 1. Tool Definition Structure
|
||||
```python
|
||||
# Example tool definition in tools.py
|
||||
def search_tool(query: str) -> list:
|
||||
"""
|
||||
Perform a web search using DuckDuckGo.
|
||||
|
||||
Args:
|
||||
query (str): The search query string.
|
||||
|
||||
Returns:
|
||||
list: Search results with title, url, and snippet.
|
||||
"""
|
||||
# Function implementation...
|
||||
```
|
||||
|
||||
### 2. Tool Dictionary Format
|
||||
```python
|
||||
tools_dict = {
|
||||
'search_tool': {
|
||||
'type': 'function',
|
||||
'function': {
|
||||
'name': 'search_tool',
|
||||
'description': '...',
|
||||
'parameters': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'query': {'type': 'string'}
|
||||
}
|
||||
}
|
||||
},
|
||||
'callable': search_tool # The actual Python function
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## The Two-Part System
|
||||
|
||||
### Part 1: OpenAI API Communication
|
||||
```python
|
||||
# task_tools: What OpenAI understands
|
||||
task_tools = []
|
||||
tool_def = tools_dict[tool_name].copy()
|
||||
callable_func = tool_def.pop("callable") # Remove the Python function
|
||||
task_tools.append(tool_def) # Add clean JSON-serializable definition
|
||||
```
|
||||
|
||||
### Part 2: Function Execution
|
||||
```python
|
||||
# role_tools: What your code executes
|
||||
role_tools = []
|
||||
role_tools.append(callable_func) # Store the actual function
|
||||
agent.tools = role_tools # Give agent access to executable functions
|
||||
```
|
||||
|
||||
## Putting It All Together
|
||||
|
||||
```python
|
||||
# Initialize empty lists
|
||||
role_tools = [] # For executable functions
|
||||
task_tools = [] # For OpenAI API definitions
|
||||
|
||||
# Process each tool
|
||||
for tool_name in tools_list:
|
||||
if tool_name in tools_dict:
|
||||
# 1. Get the tool definition
|
||||
tool_def = tools_dict[tool_name].copy()
|
||||
|
||||
# 2. Separate the callable function
|
||||
callable_func = tool_def.pop("callable")
|
||||
|
||||
# 3. Store the function for execution
|
||||
role_tools.append(callable_func)
|
||||
|
||||
# 4. Store the API definition
|
||||
task_tools.append(tool_def)
|
||||
|
||||
# 5. Give agent access to functions
|
||||
agent.tools = role_tools
|
||||
|
||||
# Create task with API definitions
|
||||
task = Task(
|
||||
description="...",
|
||||
tools=task_tools, # OpenAI API will use these
|
||||
agent=agent, # Agent has access to callable functions
|
||||
# ... other parameters ...
|
||||
)
|
||||
```
|
||||
|
||||
## Why This Works
|
||||
|
||||
1. **API Communication**
|
||||
- OpenAI API receives clean JSON tool definitions
|
||||
- No Python functions that would cause serialization errors
|
||||
|
||||
2. **Function Execution**
|
||||
- Agent has access to actual Python functions
|
||||
- Can execute tools when OpenAI decides to use them
|
||||
|
||||
3. **Separation of Concerns**
|
||||
- `task_tools`: Describes what tools can do (for OpenAI)
|
||||
- `role_tools`: Actually does the work (for Python)
|
||||
|
||||
## Common Errors and Solutions
|
||||
|
||||
1. **"Invalid type for 'tools[0]'"**
|
||||
- Cause: Sending null or invalid tool definition to OpenAI
|
||||
- Solution: Use proper tool definition format in `task_tools`
|
||||
|
||||
2. **"Object of type function is not JSON serializable"**
|
||||
- Cause: Trying to send Python function to OpenAI API
|
||||
- Solution: Remove callable function from API definition
|
||||
|
||||
3. **"Tool is not callable"**
|
||||
- Cause: Agent doesn't have access to executable functions
|
||||
- Solution: Set `agent.tools = role_tools`
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. Always initialize both `task_tools` and `role_tools` lists
|
||||
2. Make clean copies of tool definitions to avoid modifying originals
|
||||
3. Keep tool definitions JSON-serializable for API communication
|
||||
4. Ensure agents have access to callable functions
|
||||
5. Document tool parameters and return values clearly
|
||||
|
||||
This structure maintains clean separation between API communication and actual function execution, making your AI agent system both reliable and maintainable.
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "PraisonAI"
|
||||
version = "2.0.25"
|
||||
version = "2.0.27"
|
||||
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human–agent collaboration."
|
||||
readme = "README.md"
|
||||
license = ""
|
||||
@@ -84,7 +84,7 @@ autogen = ["pyautogen>=0.2.19", "praisonai-tools>=0.0.7", "crewai"]
|
||||
|
||||
[tool.poetry]
|
||||
name = "PraisonAI"
|
||||
version = "2.0.25"
|
||||
version = "2.0.27"
|
||||
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human–agent collaboration."
|
||||
authors = ["Mervin Praison"]
|
||||
license = ""
|
||||
|
||||
Reference in new issue
Block a user