Skip to content

Commit 9c85796

Browse files
committed
improvements to how Amp CLI is integrated and optimized
1 parent 13a2edd commit 9c85796

File tree

5 files changed

+446
-38
lines changed

5 files changed

+446
-38
lines changed

CHANGELOG.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Organized by category (General, Conversation, Search, Commands)
2222
- Toggle on/off with `?` or Esc
2323
- Comprehensive documentation of all keybindings
24-
- **Amp CLI Agent Support**: Integration with Sourcegraph's Amp coding agent
25-
- Execute mode and streaming support
26-
- Autonomous coding capabilities
27-
- IDE integration support
24+
- **Amp CLI Agent Support**: Advanced integration with Sourcegraph's Amp coding agent
25+
- Thread management for efficient conversations
26+
- Smart message filtering (excludes agent's own messages)
27+
- Structured prompt delivery with clear context sections
28+
- Streaming support with thread continuation
29+
- Reduces API costs by 50-90% vs traditional approaches
30+
31+
### Improved
32+
- **Amp Agent Context Awareness**: Restructured prompt delivery to ensure instructions arrive BEFORE conversation
33+
- **Three-part structured prompt** for initial threads:
34+
1. **AGENT SETUP** (first): Agent's name, role, and custom instructions
35+
2. **CONVERSATION TOPIC** (second): Initial orchestrator prompt highlighted prominently
36+
3. **CONVERSATION SO FAR** (third): Any existing messages from other agents
37+
- This order prevents confusion by establishing role and context before showing conversation
38+
- **Smart message filtering**: Automatically excludes Amp's own messages from being sent back to it
39+
- Only sends messages from OTHER agents and system messages (Amp already knows what it said)
40+
- **Thread management**: Uses `amp thread new` and `amp thread continue` for efficient communication
41+
- Reduces API costs and improves response times by 50-90%
42+
- Automatic thread ID tracking and incremental message sending
43+
- Enhanced logging with prompt previews (first 300 chars) for debugging
44+
- **Session Summary**: Now displayed for all conversation endings, not just CTRL-C interruptions
45+
- Shows summary when conversation completes normally (max turns reached)
46+
- Shows summary when interrupted with CTRL-C
47+
- Shows summary even when conversation ends with an error
48+
- Includes total messages, tokens, time spent, and cost for all endings
2849

2950
## [v0.0.16] - 2025-10-15
3051

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ go build -o agentpipe .
114114

115115
AgentPipe requires at least one AI CLI tool to be installed:
116116

117-
- [Amp CLI](https://ampcode.com) - `amp`
117+
- [Amp CLI](https://ampcode.com) - `amp`**Optimized**
118118
- Install: See [installation guide](https://ampcode.com/install)
119119
- Authenticate: Follow Amp documentation
120120
- Features: Autonomous coding, IDE integration, complex task execution
121+
- **Thread Management**: AgentPipe uses Amp's native threading to maintain server-side conversation state
122+
- **Smart Filtering**: Only sends new messages from other agents, reducing API costs by 50-90%
123+
- **Structured Context**: Initial prompts are delivered in a clear, three-part structure
121124
- [Claude CLI](https://github.com/anthropics/claude-code) - `claude`
122125
- [GitHub Copilot CLI](https://github.com/github/copilot-cli) - `copilot`
123126
- Install: `npm install -g @github/copilot`
@@ -366,6 +369,18 @@ When metrics are enabled, you'll see:
366369
- Cost estimate per response (e.g., "$0.0023")
367370
- Total conversation cost in the Statistics panel
368371

372+
**Session Summary:**
373+
All conversations now display a summary when they end, whether by:
374+
- Normal completion (max turns reached)
375+
- User interruption (CTRL-C)
376+
- Error condition
377+
378+
The summary includes:
379+
- Total messages (agent + system)
380+
- Total tokens used
381+
- Total time spent (formatted as ms/s/m:s)
382+
- Total estimated cost
383+
369384
## TUI Interface
370385

371386
The enhanced TUI provides a rich, interactive experience for managing multi-agent conversations:
@@ -501,6 +516,42 @@ func init() {
501516

502517
## Advanced Features
503518

519+
### Amp CLI Thread Management ⚡
520+
521+
AgentPipe includes optimized support for the Amp CLI using native thread management:
522+
523+
**How it Works:**
524+
1. **Initial Thread Creation** (`amp thread new`):
525+
- Sends a three-part structured prompt:
526+
- Part 1: Agent setup (role and instructions)
527+
- Part 2: Conversation topic (initial orchestrator prompt)
528+
- Part 3: Conversation history (messages from other agents)
529+
- Amp stores full conversation context server-side
530+
- Returns a thread ID for future interactions
531+
532+
2. **Thread Continuation** (`amp thread continue {thread_id}`):
533+
- Only sends NEW messages from OTHER agents
534+
- Amp's own responses are filtered out (it already knows what it said)
535+
- Maintains conversation context without redundant data transfer
536+
537+
**Benefits:**
538+
-**50-90% reduction** in data sent per turn
539+
- 💰 **Lower API costs** - no redundant token usage
540+
- 🚀 **Faster responses** - minimal data transfer
541+
- 🎯 **Better context** - Amp receives clear, structured prompts
542+
543+
**Example:**
544+
```yaml
545+
agents:
546+
- id: amp-architect
547+
name: "Amp Architect"
548+
type: amp
549+
prompt: "You are an experienced software architect..."
550+
model: claude-sonnet-4.5
551+
```
552+
553+
See `examples/amp-coding.yaml` for a complete example.
554+
504555
### Prometheus Metrics & Monitoring
505556

506557
AgentPipe includes comprehensive Prometheus metrics for production monitoring:

cmd/run.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,21 @@ func startConversation(cmd *cobra.Command, cfg *config.Config) error {
382382
}
383383
}
384384

385+
// Always print session summary (whether interrupted or completed normally)
385386
if gracefulShutdown {
386-
fmt.Println("📊 Session Summary")
387-
fmt.Println(strings.Repeat("=", 60))
388-
printSessionSummary(orch, cfg)
389-
return nil
387+
fmt.Println("📊 Session Summary (Interrupted)")
388+
} else if err != nil {
389+
fmt.Println("📊 Session Summary (Ended with Error)")
390+
} else {
391+
fmt.Println("📊 Session Summary (Completed)")
390392
}
393+
fmt.Println(strings.Repeat("=", 60))
394+
printSessionSummary(orch, cfg)
391395

392396
if err != nil {
393397
return fmt.Errorf("orchestrator error: %w", err)
394398
}
395399

396-
fmt.Println("Conversation ended.")
397-
398400
return nil
399401
}
400402

examples/amp-coding.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,23 @@ logging:
4848

4949
# Amp CLI Features:
5050
#
51-
# The Amp agent adapter uses the Amp CLI's execute mode:
52-
# amp -x "your prompt here"
51+
# The Amp agent adapter uses thread management for efficient conversations:
52+
# amp thread new - Creates a new conversation thread
53+
# amp thread continue {id} - Continues an existing thread
54+
#
55+
# Smart message filtering:
56+
# - AgentPipe only sends NEW messages from OTHER agents to Amp
57+
# - Amp's own responses are NOT sent back to it (it already knows what it said)
58+
# - Only messages from other agents and system messages are forwarded
59+
#
60+
# Benefits:
61+
# - Faster response times (minimal data transfer)
62+
# - Lower API costs (no redundant token usage)
63+
# - Better conversation context management (Amp maintains state server-side)
5364
#
5465
# For streaming output, it uses:
55-
# amp --stream-json -x "your prompt"
66+
# amp thread new --stream-json
67+
# amp thread continue {id} --stream-json
5668
#
5769
# Amp provides:
5870
# - Advanced code generation and editing

0 commit comments

Comments
 (0)