# Activity Tracker Agent - Python Implementation

Member engagement analysis agent using indus-agents framework with Anthropic Provider (GLM-4.7 via Z.AI).

## Overview

This agent analyzes church member activity patterns and calculates engagement scores using comprehensive activity data from Supabase. It generates professional, actionable analysis reports for pastoral care teams.

## Features

- **7 Activity Types with Weighted Scoring**
  - attendance (3 points)
  - volunteering (5 points)
  - donation (4 points)
  - prayer_request (2 points)
  - small_group (3 points)
  - event_registration (2 points)
  - content_engagement (1 point)

- **5 Engagement Levels**
  - highly_active (80-100)
  - active (60-79)
  - moderate (40-59)
  - low (20-39)
  - inactive (0-19)

- **Comprehensive Analysis Reports**
  - Activity patterns and trends
  - Behavioral insights
  - Risk assessment
  - Pastoral care recommendations
  - Action items for staff

- **Batch Processing Support**
  - Analyze 1-20 members at once
  - Consolidated reports
  - Efficient data processing

## Prerequisites

1. **Environment Variables**

Create or update `.env` file in project root:

```bash
# Anthropic Provider (Z.AI)
ANTHROPIC_API_KEY=your-z-ai-api-key
ANTHROPIC_MODEL=glm-4.7
ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
LLM_PROVIDER=anthropic
```

2. **Dependencies**

All dependencies are included in the main indus-agents project.

3. **Data Fetcher Scripts**

The agent expects TypeScript data fetcher scripts to exist:
- `activity_tracker_data_fetcher.ts` - Fetches member data from Supabase
- `store_activity_data.ts` - Stores analysis results to Supabase

These scripts should be copied from the original folder or created based on your Supabase schema.

## Usage

### Single Member Analysis

```bash
python activity-tracker-agent/agent.py --member_id "550e8400-e29b-41d4-a716-446655440000"
```

### Batch Analysis (Multiple Members)

```bash
python activity-tracker-agent/agent.py --member_ids "uuid1,uuid2,uuid3"
```

### Interactive Mode

```bash
python activity-tracker-agent/agent.py --interactive
```

Then type your requests:
```
You: Analyze member 550e8400-e29b-41d4-a716-446655440000
You: Batch analyze members uuid1,uuid2,uuid3
You: quit
```

### Custom Model

```bash
python activity-tracker-agent/agent.py --member_id "uuid" --model "claude-sonnet-4-5-20250929"
```

## Workflow

The agent follows this systematic workflow (from `prompt.md`):

1. **Create Todo List** - Uses TodoWrite to track progress
2. **Run Data Fetcher** - Executes TypeScript script to fetch from Supabase
3. **Verify Data Files** - Checks for JSON files in `activity_tracker_data/`
4. **Read Generated Data** - Parses members, interactions, activities
5. **Analyze Activity Patterns** - Calculates engagement scores and patterns
6. **Generate Reports** - Creates comprehensive markdown analysis
7. **Store Results** - Runs TypeScript script to save to Supabase
8. **Clean Up** - Removes temporary data files

## Output

The agent generates comprehensive analysis reports in markdown format:

```
activity_tracking_analysis_comprehensive_<MEMBER_ID>.md
```

Each report includes:
- Executive Summary
- Member Profile
- Engagement Score Breakdown (all 7 activity types)
- Engagement Analysis
- Activity Patterns
- Behavioral Insights
- Risk Assessment
- Pastoral Care Recommendations
- Action Items Summary
- Data Reference
- Conclusion

## Directory Structure

```
activity-tracker-agent/
├── agent.py                              # Main Python agent (this file)
├── prompt.md                             # Agent system prompt & instructions
├── README.md                             # This file
├── activity_tracker_data_fetcher.ts     # Data fetcher (from original)
├── store_activity_data.ts                # Storage script (from original)
└── activity_tracker_data/                # Temporary data folder
    ├── members.json                      # Generated by fetcher
    ├── member_interactions.json          # Generated by fetcher
    └── member_activities.json            # Generated by fetcher
```

## Comparison with TypeScript Version

| Feature | TypeScript (Original) | Python (This) |
|---------|----------------------|---------------|
| Provider | Anthropic Claude SDK | indus-agents with Anthropic |
| Model | claude-sonnet-4-5 | glm-4.7 (via Z.AI) |
| Language | TypeScript | Python |
| Framework | Claude Agent SDK | indus-agents |
| Tools | SDK built-in | Bash, Read, Write, Glob, Grep, TodoWrite |
| Prompt | prompt.md | Same prompt.md |
| Workflow | Same | Same |
| Output | Markdown reports | Same markdown reports |

## Key Differences

1. **Framework**: Uses indus-agents instead of Claude Agent SDK
2. **Model**: Uses GLM-4.7 via Z.AI (Anthropic-compatible API)
3. **Language**: Python instead of TypeScript
4. **Tools**: Uses indus-agents tool ecosystem
5. **Configuration**: Uses .env for all settings

## Example Output Structure

```markdown
# Activity Tracking Analysis Report

## Executive Summary
...

## Member Profile
- Name: John Doe
- Engagement Score: 75/100 (Active)
- Last Activity: 2024-01-15

## Engagement Score Breakdown
1. Content Engagement: 45 interactions (45 points)
2. Volunteering: 8 interactions (40 points)
...

## Pastoral Care Recommendations
### Immediate Actions (Week 1-2)
- Schedule one-on-one coffee meeting
- Invite to upcoming volunteer orientation
...
```

## Troubleshooting

### Error: ANTHROPIC_API_KEY not set
```bash
# Add to .env file:
ANTHROPIC_API_KEY=your-api-key-here
```

### Error: prompt.md not found
```bash
# Ensure prompt.md is in the same directory as agent.py
ls activity-tracker-agent/prompt.md
```

### Error: Data fetcher not found
```bash
# Copy or create the TypeScript fetcher scripts:
cp path/to/original/activity_tracker_data_fetcher.ts activity-tracker-agent/
cp path/to/original/store_activity_data.ts activity-tracker-agent/
```

### No output files
```bash
# Check if data was fetched:
ls activity-tracker-agent/activity_tracker_data/
```

## Cost Tracking

The agent tracks token usage and costs:
- Input tokens: $3.00 per million
- Output tokens: $15.00 per million
- Cache creation: $3.75 per million
- Cache read: $0.30 per million

Cost summary is displayed after completion.

## Support

For issues or questions:
1. Check the prompt.md for detailed specifications
2. Review the workflow in this README
3. Verify environment variables are set correctly
4. Ensure data fetcher scripts are available

## License

Same as indus-agents project.
