[kimi] Centralize agent token rules and hooks for automations (#711) #792

Merged
kimi merged 1 commits from kimi/issue-711 into main 2026-03-21 21:44:35 +00:00
Collaborator

Fixes #711

Summary

This PR centralizes agent token rules and hooks for automations as described in the Token Economy v1 milestone.

Changes

1. Token Rules Configuration (timmy_automations/config/token_rules.yaml)

Defines the complete token economy:

  • Events: 17 event types covering triage, Daily Run, PR merges, tests, and operations
  • Rewards/penalties: Configurable per event (e.g., pr_merged: +10, automation_failure: -2)
  • Gating thresholds: Minimum tokens required for sensitive operations (e.g., pr_merge: 0, sensitive_config_change: 50)
  • Daily limits: Per-category caps to prevent gaming (e.g., triage.max_earn: 100)
  • Audit settings: Transaction logging for Timmy inspection

2. Token Rules Helper Module (timmy_automations/utils/token_rules.py)

Provides a clean API for automations:

  • TokenRules.get_delta(event_name) - Get token delta for an event
  • TokenRules.compute_transaction(...) - Full transaction with gating and limit checks
  • TokenRules.check_gate(operation, current_tokens) - Verify agent can perform operation
  • get_token_delta(), compute_token_reward() - Convenience functions
  • Graceful fallback if PyYAML unavailable or config missing

3. Daily Run Integration (timmy_automations/daily_run/orchestrator.py)

First automation path using the token helpers:

  • Computes daily_run_completed reward (+5 tokens) on successful completion
  • Computes golden_path_generated reward (+3 tokens) when agenda created
  • Shows token rewards in output (both JSON and text modes)
  • Computes automation_failure penalty (-2 tokens) on errors

4. Comprehensive Tests (tests/timmy_automations/test_token_rules.py)

Covers:

  • YAML loading and fallback defaults
  • Event delta calculations
  • Gating threshold enforcement
  • Daily limit tracking
  • Transaction computation
  • Convenience functions

Acceptance Criteria

  • Token rules exist in config and are used by helpers
  • It is easy to modify rewards and thresholds without code changes
  • At least one automation path uses these helpers (Daily Run orchestrator)

Testing

tox -e unit  # All 2765 tests pass
tox -e lint  # Clean
Fixes #711 ## Summary This PR centralizes agent token rules and hooks for automations as described in the Token Economy v1 milestone. ## Changes ### 1. Token Rules Configuration (`timmy_automations/config/token_rules.yaml`) Defines the complete token economy: - **Events**: 17 event types covering triage, Daily Run, PR merges, tests, and operations - **Rewards/penalties**: Configurable per event (e.g., `pr_merged: +10`, `automation_failure: -2`) - **Gating thresholds**: Minimum tokens required for sensitive operations (e.g., `pr_merge: 0`, `sensitive_config_change: 50`) - **Daily limits**: Per-category caps to prevent gaming (e.g., `triage.max_earn: 100`) - **Audit settings**: Transaction logging for Timmy inspection ### 2. Token Rules Helper Module (`timmy_automations/utils/token_rules.py`) Provides a clean API for automations: - `TokenRules.get_delta(event_name)` - Get token delta for an event - `TokenRules.compute_transaction(...)` - Full transaction with gating and limit checks - `TokenRules.check_gate(operation, current_tokens)` - Verify agent can perform operation - `get_token_delta()`, `compute_token_reward()` - Convenience functions - Graceful fallback if PyYAML unavailable or config missing ### 3. Daily Run Integration (`timmy_automations/daily_run/orchestrator.py`) First automation path using the token helpers: - Computes `daily_run_completed` reward (+5 tokens) on successful completion - Computes `golden_path_generated` reward (+3 tokens) when agenda created - Shows token rewards in output (both JSON and text modes) - Computes `automation_failure` penalty (-2 tokens) on errors ### 4. Comprehensive Tests (`tests/timmy_automations/test_token_rules.py`) Covers: - YAML loading and fallback defaults - Event delta calculations - Gating threshold enforcement - Daily limit tracking - Transaction computation - Convenience functions ## Acceptance Criteria - [x] Token rules exist in config and are used by helpers - [x] It is easy to modify rewards and thresholds without code changes - [x] At least one automation path uses these helpers (Daily Run orchestrator) ## Testing ```bash tox -e unit # All 2765 tests pass tox -e lint # Clean ```
kimi added 1 commit 2026-03-21 21:44:04 +00:00
feat: Centralize agent token rules and hooks for automations (#711)
Some checks failed
Tests / lint (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
d3eb5c31bf
- Add token_rules.yaml config defining events, rewards, penalties, and gating thresholds
- Create token_rules.py helper module for loading config and computing token deltas
- Update orchestrator.py to compute token rewards for Daily Run completion
- Add comprehensive tests for token_rules module

The token economy is now configurable without code changes:
- Events: triage actions, Daily Run completions, PR merges, test fixes
- Rewards/penalties per event type
- Gating thresholds for sensitive operations
- Daily limits per category
- Audit settings for transaction logging

Fixes #711
kimi merged commit dfe40f5fe6 into main 2026-03-21 21:44:35 +00:00
kimi deleted branch kimi/issue-711 2026-03-21 21:44:36 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#792