mirror of https://github.com/aliasrobotics/cai.git
Add custom tool example to agent (#347)
add custom tool example Co-authored-by: Maria <maria@aliasrobotics.com>
This commit is contained in:
parent
28241117f2
commit
d6e8b0d561
|
|
@ -184,7 +184,7 @@ custom_agent = Agent(
|
||||||
|
|
||||||
### Extend Existing Agents
|
### Extend Existing Agents
|
||||||
|
|
||||||
This example demonstrates extending Red Team Agent to write 'Red Team Agent at your service.' at the end of each message:
|
This example demonstrates extending Red Team Agent **instructions** to write 'Red Team Agent at your service.' at the end of each message:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from cai.cli import run_cai_cli
|
from cai.cli import run_cai_cli
|
||||||
|
|
@ -209,6 +209,35 @@ redteam_agent.instructions = modified_prompt
|
||||||
run_cai_cli(redteam_agent)
|
run_cai_cli(redteam_agent)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
In the same way you could add a **custom/existing tools**:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from cai.cli import run_cai_cli
|
||||||
|
from cai.agents.red_teamer import redteam_agent
|
||||||
|
from cai.sdk.agents.tool import function_tool
|
||||||
|
from cai.tools.reconnaissance.shodan import shodan_search, shodan_host_info
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# Create new fucntion for a tool
|
||||||
|
@function_tool
|
||||||
|
def hello_world() -> str:
|
||||||
|
"""
|
||||||
|
Prints Hello, World!
|
||||||
|
Args: None
|
||||||
|
Returns: str: A greeting message.
|
||||||
|
"""
|
||||||
|
return "Hello, World!"
|
||||||
|
|
||||||
|
# Load environment variables from .env file
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
# Add the new function and CAI shodan tools to the red team agent
|
||||||
|
redteam_agent.tools.extend([shodan_search, shodan_host_info, hello_world])
|
||||||
|
|
||||||
|
# Run the red team agent
|
||||||
|
run_cai_cli(redteam_agent)
|
||||||
|
```
|
||||||
|
|
||||||
If you want to create your own custom tools for your agents, see the [tools documentation](tools.md) for detailed instructions.
|
If you want to create your own custom tools for your agents, see the [tools documentation](tools.md) for detailed instructions.
|
||||||
|
|
||||||
If you want to create Multi-Agent Patterns, see [multi_agent documentation](multi_agent.md) for orchestration patterns.
|
If you want to create Multi-Agent Patterns, see [multi_agent documentation](multi_agent.md) for orchestration patterns.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue