From 4d7f1d9e6ead1c7ed779465b55e34871756e24d6 Mon Sep 17 00:00:00 2001 From: Shayan Rais Date: Mon, 3 Nov 2025 20:50:10 +0500 Subject: [PATCH] allowed agent calling within an agent --- .claude/commands/weather-karachi.md | 19 ++++ .claude/commands/weather.md | 16 +-- docs/AGENTS.md | 2 +- docs/PROMPTS.md | 6 +- docs/WEATHER.md | 167 ++++++++++++++++++++++++++++ output/output.md | 8 +- 6 files changed, 197 insertions(+), 21 deletions(-) create mode 100644 .claude/commands/weather-karachi.md create mode 100644 docs/WEATHER.md diff --git a/.claude/commands/weather-karachi.md b/.claude/commands/weather-karachi.md new file mode 100644 index 0000000..571e7c3 --- /dev/null +++ b/.claude/commands/weather-karachi.md @@ -0,0 +1,19 @@ +--- +description: Fetch and transform weather data for Karachi +model: haiku +--- + +# Weather Karachi Command + +Fetch the current temperature for Karachi, Pakistan and apply transformations. + +## Workflow + +1. Use the weather-fetcher agent to retrieve the current temperature from wttr.in API +2. Use the weather-transformer agent to read transformation rules from input/input.md and apply them to the temperature +3. Write the results to output/output.md + +Launch the agents sequentially (not in parallel) and provide a clear summary showing: +- Original temperature +- Transformation applied +- Final result diff --git a/.claude/commands/weather.md b/.claude/commands/weather.md index 4872137..d25a733 100644 --- a/.claude/commands/weather.md +++ b/.claude/commands/weather.md @@ -1,20 +1,10 @@ --- -description: Fetch and transform weather data for a city -argument-hint: +description: Fetch and transform weather data for Karachi model: haiku --- # Weather Command -Fetch the current temperature for ${1:-Karachi}, Pakistan and apply transformations. +Execute the weather-karachi command to fetch and transform temperature data. -## Workflow - -1. Use the weather-fetcher agent to retrieve the current temperature from wttr.in API -2. Use the weather-transformer agent to read transformation rules from input/input.md and apply them to the temperature -3. Write the results to output/output.md - -Launch the agents sequentially (not in parallel) and provide a clear summary showing: -- Original temperature -- Transformation applied -- Final result +Use the SlashCommand tool to execute `/weather-karachi`. diff --git a/docs/AGENTS.md b/docs/AGENTS.md index ecaca07..4cef772 100644 --- a/docs/AGENTS.md +++ b/docs/AGENTS.md @@ -101,7 +101,7 @@ After updating the orchestrator agent definition, test it by invoking the orches ```bash # Via slash command -/weather +/weather-karachi # Or directly via Task tool Task(subagent_type="weather-orchestrator", description="Run weather workflow", prompt="Orchestrate the complete weather workflow", model="haiku") diff --git a/docs/PROMPTS.md b/docs/PROMPTS.md index 32d50e4..d220c40 100644 --- a/docs/PROMPTS.md +++ b/docs/PROMPTS.md @@ -20,7 +20,7 @@ see the table in @PROMPTS.md of Agent Invocation and Command Invocation and cros | From | How | Example | |----------------------|------------------------|-------------------------------------| | Claude CLI | Prompt | use the weather command to fetch the weather | - | Claude CLI | /command-name | /weather | - | /agents/Agents.md | SlashCommand tool | SlashCommand(command="/weather Karachi") | - | Another /command | SlashCommand tool | SlashCommand(command="/weather Karachi") | + | Claude CLI | /command-name | /weather-karachi | + | /agents/Agents.md | SlashCommand tool | SlashCommand(command="/weather-karachi") | + | Another /command | SlashCommand tool | SlashCommand(command="/weather-karachi") | diff --git a/docs/WEATHER.md b/docs/WEATHER.md new file mode 100644 index 0000000..5a81d07 --- /dev/null +++ b/docs/WEATHER.md @@ -0,0 +1,167 @@ +# Weather Karachi System Flow + +This document describes the complete flow of the weather data fetching and transformation system. + +## System Overview + +The weather system consists of slash commands and specialized agents that work together to fetch and transform temperature data for Karachi, Pakistan. + +## Flow Diagram + +``` +┌─────────────────────────────────────────────────────────────────┐ +│ User Interaction │ +└─────────────────────────────────────────────────────────────────┘ + │ + ▼ + ┌──────────────────┐ + │ /weather │ + │ Command │ + └──────────────────┘ + │ + │ calls + ▼ + ┌──────────────────┐ + │ /weather-karachi │ + │ Command │ + └──────────────────┘ + │ + │ Step 1 (Sequential) + ▼ + ┌────────────────────────┐ + │ weather-fetcher │ + │ Agent │ + │ (subagent_type) │ + └────────────────────────┘ + │ + ▼ + ┌────────────────────────┐ + │ wttr.in API │ + │ Fetch Temperature │ + │ for Karachi │ + └────────────────────────┘ + │ + │ Returns: 26°C + ▼ + │ + │ Step 2 (Sequential) + ▼ + ┌─────────────────────────┐ + │ weather-transformer │ + │ Agent │ + │ (subagent_type) │ + └─────────────────────────┘ + │ + ▼ + ┌─────────────────────────┐ + │ input/input.md │ + │ Read Transform Rules │ + └─────────────────────────┘ + │ + │ Reads: "add +10" + ▼ + ┌────────────────────────┐ + │ Apply Transform │ + │ 26 + 10 = 36°C │ + └────────────────────────┘ + │ + ▼ + ┌────────────────────────┐ + │ output/output.md │ + │ Write Results │ + └────────────────────────┘ + │ + ▼ + ┌────────────────────────┐ + │ Display Summary │ + │ to User │ + └────────────────────────┘ +``` + +## Component Details + +### 1. Slash Commands + +#### `/weather` +- **Location**: `.claude/commands/weather.md` +- **Purpose**: Entry point for weather operations +- **Action**: Calls `/weather-karachi` command +- **Model**: haiku + +#### `/weather-karachi` +- **Location**: `.claude/commands/weather-karachi.md` +- **Purpose**: Orchestrates the weather fetching and transformation workflow +- **Action**: Launches two specialized agents sequentially +- **Model**: haiku + +### 2. Specialized Agents + +#### `weather-fetcher` +- **Location**: `.claude/agents/weather-fetcher.md` +- **Purpose**: Fetch real-time temperature data +- **Data Source**: wttr.in API for Karachi, Pakistan +- **Output**: Temperature in Celsius (numeric value) +- **Tools Available**: WebFetch + +#### `weather-transformer` +- **Location**: `.claude/agents/weather-transformer.md` +- **Purpose**: Apply mathematical transformations to temperature data +- **Input Source**: `input/input.md` (transformation rules) +- **Output Destination**: `output/output.md` (formatted results) +- **Tools Available**: Read, Write + +### 3. Data Files + +#### `input/input.md` +- **Purpose**: Stores transformation rules +- **Format**: Natural language instructions (e.g., "add +10 in the result") +- **Access**: Read by weather-transformer agent + +#### `output/output.md` +- **Purpose**: Stores formatted transformation results +- **Format**: Structured markdown with sections: + - Original Temperature + - Transformation Applied + - Final Result + - Calculation Details + +## Execution Flow + +1. **User Invocation**: User runs `/weather` command +2. **Command Delegation**: `/weather` delegates to `/weather-karachi` +3. **Sequential Agent Execution**: + - **Step 1**: `weather-fetcher` agent fetches current temperature from wttr.in + - **Step 2**: `weather-transformer` agent: + - Reads transformation rules from `input/input.md` + - Applies rules to the fetched temperature + - Formats and writes results to `output/output.md` +4. **Result Display**: Summary shown to user with: + - Original temperature + - Transformation rule applied + - Final transformed result + +## Example Execution + +``` +Input: /weather +├─ Calls: /weather-karachi +│ ├─ Agent: weather-fetcher +│ │ └─ Result: 26°C +│ ├─ Agent: weather-transformer +│ │ ├─ Reads: input/input.md ("add +10") +│ │ ├─ Calculates: 26 + 10 = 36°C +│ │ └─ Writes: output/output.md +│ └─ Output: +│ ├─ Original: 26°C +│ ├─ Transform: Add +10 +│ └─ Result: 36°C +``` + +## Key Design Principles + +1. **Separation of Concerns**: Each component has a single, clear responsibility +2. **Sequential Execution**: Agents run in order to ensure data dependencies are met +3. **Specialized Agents**: Task-specific agents with minimal tool access +4. **Command Chaining**: Simple commands can delegate to more complex workflows +5. **Configurable Transformations**: Rules stored externally in input files +6. **Structured Output**: Results formatted consistently in output files diff --git a/output/output.md b/output/output.md index e1117b5..179be7b 100644 --- a/output/output.md +++ b/output/output.md @@ -1,13 +1,13 @@ # Weather Transformation Results -**Original Temperature:** 50°C +**Original Temperature:** 26°C **Transformation Applied:** Add +10 to the result -**Final Result:** 60°C +**Final Result:** 36°C ## Calculation Details -- Starting value: 50°C +- Starting value: 26°C - Operation: +10 -- Result: 50 + 10 = 60°C +- Result: 26 + 10 = 36°C