Skip to content

Add data analyst agent setup and session runner scripts#269

Open
MelodyBorg wants to merge 1 commit intonextlevelbuilder:mainfrom
MelodyBorg:claude/create-data-analyst-agent-CWIiD
Open

Add data analyst agent setup and session runner scripts#269
MelodyBorg wants to merge 1 commit intonextlevelbuilder:mainfrom
MelodyBorg:claude/create-data-analyst-agent-CWIiD

Conversation

@MelodyBorg
Copy link
Copy Markdown

Summary

Add two new TypeScript scripts to set up and run an Anthropic managed agent for data analysis tasks with Amplitude MCP integration.

Key Changes

  • agents/data-analyst-setup.ts — One-time setup script that:

    • Creates a cloud environment with unrestricted networking
    • Optionally creates a vault and stores Amplitude MCP OAuth credentials
    • Creates a managed agent configured with Claude Sonnet 4.6, a data analysis system prompt, and both the agent toolset and Amplitude MCP tools
    • Outputs environment variables needed for session execution
  • agents/data-analyst-session.ts — Runtime script that:

    • Creates and manages interactive sessions with the pre-created agent
    • Accepts user queries as command-line arguments
    • Implements stream-first event handling to process agent responses, custom tool calls, and session status updates
    • Handles custom tool results (with placeholder implementation for unimplemented tools)
    • Logs token usage for cost tracking
    • Lists output files generated by the agent in /mnt/session/outputs/

Notable Implementation Details

  • Stream-first ordering: Opens the event stream before sending the user message to ensure no events are missed
  • Custom tool handling: Captures custom tool calls and sends back placeholder results when tools aren't implemented
  • Session lifecycle: Properly handles terminal states (end_turn, retries_exhausted) vs. action-required states (requires_action)
  • Token tracking: Logs input, output, and cache-related token usage from model request spans
  • Flexible configuration: Supports optional agent version pinning and vault ID specification via environment variables
  • Amplitude integration: Includes OAuth credential management with optional refresh token support for the Amplitude MCP server

https://claude.ai/code/session_01LgH47h1xyCd89wPWKTRU93

Creates a two-file Anthropic Managed Agent setup for data analysis:
- agents/data-analyst-setup.ts: one-time agent/environment/vault creation
- agents/data-analyst-session.ts: per-invocation session runner with SSE streaming

Agent uses claude-sonnet-4-6, the amplitude MCP server, and the
full agent_toolset_20260401. Vault creation is optional and gated
on AMPLITUDE_ACCESS_TOKEN being present.

https://claude.ai/code/session_01LgH47h1xyCd89wPWKTRU93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants