Objective: Develop a versatile command-line interface (CLI) agent using Python and the Composio Platform . This agent will leverage Composio's framework to understand natural language commands and interact with the local file system and perform web searches through integrated tools.
Core Technology: Composio Tools Python SDK (composio_core.py)
- Key Documentation Resources:
- Composio Main Docs Overview: https://docs.composio.com/
- Installation Guide: https://docs.composio.dev/getting-started/installation
- Composio Agent Framework Concepts: (Refer to sections detailing
Agent,Tool,Actionclasses) [Example Concept: https://docs.composio.com/docs/concepts/agent] - Composio Tools Overview: https://docs.composio.com/docs/tools/overview
- Tool Calling Introduction: https://docs.composio.dev/tool-calling/introduction
- Fetching Tools: https://docs.composio.dev/tool-calling/fetching-tools
- Executing Tools: https://docs.composio.dev/tool-calling/executing-tools (Note: This link appears twice in the provided list, assuming it's a typo and referring to the same resource).
- Specific Tool Example (SerpAPI): https://docs.composio.dev/tools/serpapi
- Composio Tools List [https://docs.composio.dev/tools/introduction]
Target Audience: This prompt is intended for a Python developer familiar with CLI development and AI concepts, ready to integrate Composio.
- Language: Python 3.9+
- Core Framework: Composio Python SDK (
composio_core) - CLI Framework: Utilize
typer(recommended for modern Python CLIs) orclick.- Typer Docs: https://typer.tiangolo.com/
- Agent Logic:
- The agent should encapsulate the core intelligence, selecting and executing appropriate Composio tools based on user CLI input.
- Use Composio's
Agentclass as the central orchestrator. Understand how the agent utilizes tool descriptions and function signatures to interpret user requests. Refer to Composio Tool Calling Introduction. - The agent should be configured with the necessary tools, fetching them as needed or defining them explicitly. See Fetching Tools.
- Configuration:
- API Keys (Composio, potentially LLM provider, SerpAPI Key): Managed securely via environment variables (e.g.,
.envfile andpython-dotenvlibrary). - LLM Choice: Allow configuration (or use Composio's default) for the underlying Large Language Model driving the agent's reasoning.
- API Keys (Composio, potentially LLM provider, SerpAPI Key): Managed securely via environment variables (e.g.,
- Error Handling: Implement robust error handling for invalid commands, tool failures (including specific errors from Composio tools), file system permission issues, network errors during web search, etc. Provide clear feedback to the user.
- User Interaction: Primarily through the CLI. The agent's output (results of operations, confirmations, errors) should be displayed clearly in the terminal.
Propose a clean and scalable project structure:
composio-cli-agent/
│
├── .env # Environment variables (API keys, etc.) - DO NOT COMMIT
├── .gitignore # Git ignore file
├── requirements.txt # Python dependencies
├── README.md # Project description, setup, usage instructions
├── config/ # Optional: Configuration files (if needed beyond .env)
│ └── __init__.py
├── agent/ # Core agent logic and Composio setup
│ ├── __init__.py
│ ├── agent.py # Main Agent class definition and initialization
│ └── tools.py # Tool definitions or configuration
├── cli/ # CLI application logic
│ ├── __init__.py
│ ├── main.py # Main entry point for the CLI (using Typer/Click)
│ └── commands.py # Functions mapping CLI commands to agent actions
├── core/ # Optional: Core utilities, constants, etc.
│ ├── __init__.py
│ └── utils.py
├── tests/ # Unit and integration tests
│ ├── __init__.py
│ └── ... # Test files
│
└── scripts/ # Optional: Utility scripts (e.g., setup)
└── ...
The agent must be equipped with the following Composio tools:
-
File System Tools: (Integrate via
composio.tools.fsor equivalent Composio modules)ListDirectoryTool: List files and directories within a specified path.CreateFileTool: Create a new file (potentially with initial content).ReadFileTool: Read the content of a specified file.WriteFileTool: Write or overwrite content to a specified file.DeleteFileTool: Delete a file or directory (consider safety checks/prompts).CopyFileTool: Copy a file or directory.MoveFileTool: Move/rename a file or directory.- Reference: Look for
FileToolsManageror specific tool classes in Composio documentation regarding how to fetch and use these. Understand the execution flow described in Executing Tools.
-
Web Search Tool: (Integrate via
composio.tools.webor equivalent)WebSearchTool: Perform web searches using a search engine (e.g., Google, DuckDuckGo) and retrieve summaries or key information. This might rely on underlying services like SerpAPI.- Reference: Consult the documentation for specific web search tools, such as the Composio Serp API Qn example, to understand configuration and usage requirements (like needing a SerpAPI key). Ensure you know how to properly execute these tools using the agent.
- CLI Interface:
- A single executable command (e.g.,
composio-agent). - Subcommands or arguments to trigger specific actions or allow natural language input.
- Example commands:
composio-agent ls <path>(orcomposio-agent run "list files in /path")composio-agent cat <filepath>(orcomposio-agent run "read file /path/to/file.txt")composio-agent search <query>(orcomposio-agent run "search the web for latest AI news")composio-agent help(display available commands and agent capabilities)
- A single executable command (e.g.,
- Natural Language Interaction: Allow users to type natural language requests directly, e.g.,
composio-agent run "create a file named report.txt and write today's date into it". The agent, powered by Composio, should parse this, select the appropriate file/web tools based on intent, and execute them. This leverages Composio's core LLM capabilities for intent recognition and tool selection. - Tool Orchestration: Composio should intelligently select the correct tool(s) based on the user's natural language input. This involves understanding the descriptions and parameters of the available tools.
- Context Management: (Optional Enhancement) Maintain conversation history or context between commands if feasible within the Composio framework for follow-up actions.
- Secure Key Management: Load API keys from environment variables (
.env). Ensure proper handling and security practices.
Milestone 1: Project Setup & Basic Structure
- Goal: Initialize the project, set up the environment, and create the basic CLI structure.
- Tasks:
- Create the folder structure as defined above.
- Set up a Python virtual environment.
- Create
requirements.txtand addcomposio-py,typer,python-dotenv, and any other necessary libraries. - Installation: Follow the Installation Guide to install
composio-py. - Create
.gitignoreand.envplaceholder files. Add instructions for setting up.env(Composio API key, etc.) inREADME.md. - Implement a basic
typerapp incli/main.py. - Add a simple
helpcommand and a genericruncommand that takes raw text input. - Configure basic Composio SDK initialization (e.g., loading API keys from
.env) inagent/agent.py. - Composio Docs: Focus on SDK installation, basic setup, and environment variable configuration.
Milestone 2: File System Tool Integration
- Goal: Enable the agent to perform basic file system operations via the CLI.
- Tasks:
- Identify and import the necessary Composio file system tools (e.g.,
ListDirectoryTool,ReadFileTool,CreateFileTool). Refer to Composio's tool documentation for specifics on how these are exposed. - Configure the Composio
Agentinagent/agent.pyto include these file tools. This might involve fetching them using Composio's mechanisms or explicitly listing them. Review Fetching Tools. - In
cli/commands.py, implement functions that take CLI arguments (like file paths) and call the agent's primary execution method (e.g.,agent.run()), passing the file operation request framed as natural language. - Example: Create a
cli ls <path>command that invokes the agent withagent.run(f"list files in the directory {path}"). - Test listing directories, reading files, creating simple files using both direct CLI commands and natural language inputs via the
runcommand. - Understand how Composio handles the Executing Tools lifecycle for these file operations.
- Identify and import the necessary Composio file system tools (e.g.,
Milestone 3: Web Search Integration
- Goal: Enable the agent to perform web searches via the CLI.
- Tasks:
- Identify and import the relevant Composio web search tool (e.g.,
WebSearchToolor a specific implementation like SerpAPI). - Add the
WebSearchToolto the agent's tool configuration, ensuring any necessary API keys (like for SerpAPI) are configured via environment variables. Refer to the Composio Serp API Qn for potential requirements. - Implement CLI commands or enhance the generic
runcommand to handle web search queries (e.g.,cli search <query>orcomposio-agent run "search the web for X"). - Test the web search functionality, ensuring results are retrieved and displayed appropriately. Pay attention to how Composio formats search results.
- Verify the execution flow for web search tools using the Executing Tools documentation.
- Identify and import the relevant Composio web search tool (e.g.,
Milestone 4: Natural Language Command Execution
- Goal: Allow the agent to interpret and execute arbitrary natural language commands involving the integrated tools.
- Tasks:
- Focus on the generic
composio-agent run "<natural language command>"interface. - Ensure the
agent.pylogic correctly passes the natural language string to the ComposioAgentfor processing. This is where Composio's core LLM reasoning shines. - Test complex commands involving multiple steps or tool choices (e.g., "read the contents of
config.yaml, find lines containing 'API_KEY', and print them"). - Refine agent prompting (if possible via Composio configuration) to improve tool selection accuracy and response quality. Understand how Composio uses tool descriptions for this.
- Composio Docs: Focus on the core agent execution flow (
agent.run(...)or similar) and how it handles tool selection based on natural language input, as detailed in the Tool Calling Introduction and Executing Tools documentation.
- Focus on the generic
Milestone 5: Refinement, Testing & Documentation
- Goal: Polish the agent, add comprehensive tests, and document the project thoroughly.
- Tasks:
- Implement robust error handling and user feedback messages for all operations.
- Add confirmation prompts for potentially destructive actions (like file deletion) to enhance safety.
- Write unit and integration tests in the
tests/directory to cover core functionalities, tool interactions, and edge cases. - Write a detailed
README.mdincluding:- Project overview.
- Prerequisites (Python, Composio Account/API Key, potentially other service keys).
- Installation instructions (
pip install -r requirements.txt, linking to Installation Guide). - Configuration steps (setting
.envwith necessary keys). - Usage examples for all CLI commands and natural language interactions.
- Contribution guidelines (optional).
- Ensure code quality (linting with tools like
flake8orblack, type checking). - Package the application potentially (e.g., using
setup.pyorpyproject.tomlfor easier distribution, although not strictly required by this prompt).
Deliverables:
- A complete, functional Python project implementing the CLI agent.
- Source code organized according to the specified folder structure.
- A comprehensive
README.mdfile. requirements.txtfile listing all dependencies.- Test cases demonstrating the agent's functionality.