You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tools are functions that agents can use to interact with external systems and perform actions. They are essential for creating agents that can do more than just process text.
47
47
48
-
## Creating Custom Tool
48
+
<Tabs>
49
+
50
+
<Tabtitle="Code">
49
51
<Steps>
50
-
<Step>
51
-
Create any function that you want to use as a tool, that performs a specific task.
52
+
53
+
<Steptitle="Install PraisonAI">
54
+
Install the core package:
55
+
```bash Terminal
56
+
pip install praisonaiagents duckduckgo-search
57
+
```
58
+
</Step>
59
+
60
+
<Steptitle="Configure Environment">
61
+
```bash Terminal
62
+
export OPENAI_API_KEY=your_openai_key
63
+
```
64
+
Generate your OpenAI API key from [OpenAI](https://platform.openai.com/api-keys)
65
+
Use other LLM providers like Ollama, Anthropic, Groq, Google, etc. Please refer to the [Models](/models) for more information.
66
+
</Step>
67
+
68
+
<Steptitle="Create Agent with Tool">
69
+
Create `app.py`
70
+
<CodeGroup>
71
+
```python Single Agent
72
+
from praisonaiagents import Agent
73
+
from duckduckgo_search importDDGS
74
+
75
+
# 1. Define the tool
76
+
definternet_search_tool(query: str):
77
+
results = []
78
+
ddgs = DDGS()
79
+
for result in ddgs.text(keywords=query, max_results=5):
80
+
results.append({
81
+
"title": result.get("title", ""),
82
+
"url": result.get("href", ""),
83
+
"snippet": result.get("body", "")
84
+
})
85
+
return results
86
+
87
+
# 2. Assign the tool to an agent
88
+
search_agent = Agent(
89
+
instructions="Perform internet searches to collect relevant information.",
0 commit comments