Skip to content

Instantly share code, notes, and snippets.

@22f2000147
Last active April 3, 2026 09:00
Show Gist options
  • Select an option

  • Save 22f2000147/b4d8b5839a614f8dddeaaf45d037840e to your computer and use it in GitHub Desktop.

Select an option

Save 22f2000147/b4d8b5839a614f8dddeaaf45d037840e to your computer and use it in GitHub Desktop.
Prompt to build a CLI Agent Powered by Composio

Prompt: Build a Composio Tools Powered Python CLI Agent

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)

Target Audience: This prompt is intended for a Python developer familiar with CLI development and AI concepts, ready to integrate Composio.


I. Project Specifications

  1. Language: Python 3.9+
  2. Core Framework: Composio Python SDK (composio_core)
  3. CLI Framework: Utilize typer (recommended for modern Python CLIs) or click.
  4. Agent Logic:
    • The agent should encapsulate the core intelligence, selecting and executing appropriate Composio tools based on user CLI input.
    • Use Composio's Agent class 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.
  5. Configuration:
    • API Keys (Composio, potentially LLM provider, SerpAPI Key): Managed securely via environment variables (e.g., .env file and python-dotenv library).
    • LLM Choice: Allow configuration (or use Composio's default) for the underlying Large Language Model driving the agent's reasoning.
  6. 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.
  7. User Interaction: Primarily through the CLI. The agent's output (results of operations, confirmations, errors) should be displayed clearly in the terminal.

II. Folder Structure

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)
    └── ...

III. Toolset Definition

The agent must be equipped with the following Composio tools:

  1. File System Tools: (Integrate via composio.tools.fs or 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 FileToolsManager or specific tool classes in Composio documentation regarding how to fetch and use these. Understand the execution flow described in Executing Tools.
  2. Web Search Tool: (Integrate via composio.tools.web or 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.

IV. Key Features

  1. 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> (or composio-agent run "list files in /path")
      • composio-agent cat <filepath> (or composio-agent run "read file /path/to/file.txt")
      • composio-agent search <query> (or composio-agent run "search the web for latest AI news")
      • composio-agent help (display available commands and agent capabilities)
  2. 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.
  3. 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.
  4. Context Management: (Optional Enhancement) Maintain conversation history or context between commands if feasible within the Composio framework for follow-up actions.
  5. Secure Key Management: Load API keys from environment variables (.env). Ensure proper handling and security practices.

V. Development Milestones

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.txt and add composio-py, typer, python-dotenv, and any other necessary libraries.
    • Installation: Follow the Installation Guide to install composio-py.
    • Create .gitignore and .env placeholder files. Add instructions for setting up .env (Composio API key, etc.) in README.md.
    • Implement a basic typer app in cli/main.py.
    • Add a simple help command and a generic run command that takes raw text input.
    • Configure basic Composio SDK initialization (e.g., loading API keys from .env) in agent/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 Agent in agent/agent.py to 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 with agent.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 run command.
    • Understand how Composio handles the Executing Tools lifecycle for these file operations.

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., WebSearchTool or a specific implementation like SerpAPI).
    • Add the WebSearchTool to 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 run command to handle web search queries (e.g., cli search <query> or composio-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.

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.py logic correctly passes the natural language string to the Composio Agent for 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.

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.md including:
      • 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 .env with necessary keys).
      • Usage examples for all CLI commands and natural language interactions.
      • Contribution guidelines (optional).
    • Ensure code quality (linting with tools like flake8 or black, type checking).
    • Package the application potentially (e.g., using setup.py or pyproject.toml for 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.md file.
  • requirements.txt file listing all dependencies.
  • Test cases demonstrating the agent's functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment