From d6e8b0d561855743be871fc0beec70dc34093907 Mon Sep 17 00:00:00 2001 From: Mery-Sanz <78554738+Mery-Sanz@users.noreply.github.com> Date: Fri, 14 Nov 2025 13:50:14 +0100 Subject: [PATCH] Add custom tool example to agent (#347) add custom tool example Co-authored-by: Maria --- docs/agents.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/agents.md b/docs/agents.md index 8f0ed672..b6679c56 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -184,7 +184,7 @@ custom_agent = Agent( ### 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 from cai.cli import run_cai_cli @@ -209,6 +209,35 @@ redteam_agent.instructions = modified_prompt 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 Multi-Agent Patterns, see [multi_agent documentation](multi_agent.md) for orchestration patterns.