Skip to content

Claude/mirascope v2 migration 011 cv4jd43t5 g gp ww86 bf ea1#89

Merged
jayscambler merged 8 commits into
mainfrom
claude/mirascope-v2-migration-011CV4jd43t5GGpWW86BfEa1
Nov 12, 2025
Merged

Claude/mirascope v2 migration 011 cv4jd43t5 g gp ww86 bf ea1#89
jayscambler merged 8 commits into
mainfrom
claude/mirascope-v2-migration-011CV4jd43t5GGpWW86BfEa1

Conversation

@jayscambler
Copy link
Copy Markdown
Contributor

@jayscambler jayscambler commented Nov 12, 2025

Description

How to test

Checkout the branch

git fetch origin
git checkout <your-branch>

Test the new changes

Checklist

  • My code follows the code style of this project.
    • Fix via ruff check --fix and/or ruff format .
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Screenshots (if appropriate)

Close issues

Closes issue #


Note

Migrate the codebase to Mirascope v2 (functional prompts, tool functions, new call params), update agents/tests, add migration tooling/docs, and reorganize dependencies into granular extras.

  • Core Migration (Mirascope v2):
    • Replace prompt_template with functional prompts returning strings; update @llm.call to provider="openai:completions", model_id=, and format= across agents.
    • Convert BaseTool classes to @llm.tool functions (notably in agents/multi_source_news_verification).
    • Remove BaseDynamicConfig patterns; functions now return prompts or use context as needed.
  • Agents Updated:
    • Major refactors across academic_research, sales_intelligence, market_intelligence, recruiting_assistant, sourcing_assistant, research_assistant, hallucination_detector, knowledge_graph, enhanced_knowledge_graph, text_summarization, code_generation_execution, document_segmentation, dynamic_learning_path, game_playing_*, game_theory_analysis, multi_agent_coordinator, web_search (static tool list; prompt-returning call).
  • Tooling & Scripts:
    • Add migrate_to_v2.py migration script and test_v2_api.py to validate v2 patterns.
  • Tests:
    • Update tests/utils/mirascope_test_helpers.py for v2 (format, model_id, prompt-return checks, provider config).
  • Dependencies:
    • Restructure pyproject.toml with granular optional extras (agents, search, observability, database, web, documents, git, data, fuzzy, youtube, all-agents, dev, test).
  • Docs & PR Content:
    • Add comprehensive migration docs: AGENT_DEPENDENCIES.md, MIGRATION_*.md, updated CLAUDE.md, and PR_DESCRIPTION.md.

Written by Cursor Bugbot for commit af5f271. This will update automatically on new commits. Configure here.

- Updated pyproject.toml to mirascope>=2.0.0a1
- Created test_v2_api.py to explore v2 API patterns
- Discovered v2 is in ALPHA with extensive breaking changes:
  * prompt_template no longer exists (use @llm.prompt)
  * BaseTool no longer exists (use @llm.tool functions)
  * BaseDynamicConfig no longer exists
  * Template syntax changed: {var} → {{ var }}
  * Requires role markers: [USER], [ASSISTANT], [SYSTEM]
- Estimated full migration: 40-60 hours due to scope
- Awaiting decision on proceeding with alpha migration
Added comprehensive migration documentation:

1. MIGRATION_V2.md - Verified v2 API patterns with working examples
   - Functional prompts (no template parameter - not implemented)
   - New decorator signature: provider="openai:completions", model_id, format
   - Function-based tools with @llm.tool
   - Context pattern with llm.Context[T]

2. MIGRATION_CATALOG.md - Scope analysis
   - 45 files with mirascope imports
   - 247 prompt_template usages
   - 8 BaseTool classes
   - 97 BaseDynamicConfig usages
   - Estimated 40-60 hours total effort

3. FULL_MIGRATION_PLAN.md - Complete implementation plan
   - Detailed before/after code examples
   - Phase-by-phase migration strategy
   - Risk assessment (HIGH: alpha stability)
   - Three recommendations: wait, proceed, or hybrid
   - POC approach starting with multi_source_news_verification

4. test_v2_api.py - Working v2 examples
   - Verified all patterns work with v2.0.0-alpha.1
   - Functional prompts, calls, tools, and context

Key Finding: v2 template parameter raises NotImplementedError
- Must use functional prompts returning f-strings
- Cannot use @llm.prompt(template="...") syntax

Awaiting decision on proceeding with alpha migration.
Completed Work:
1. Converted all 7 BaseTool classes to @llm.tool functions in POC agent
   - web_search, fact_check_search, academic_search
   - government_data_search, reverse_image_search
   - social_media_verification, expert_source_search
   - All tested and working with v2 API

2. Created migration automation script (migrate_to_v2.py)
   - Automatically updates imports
   - Converts @llm.call decorator parameters
   - Detects manual conversion needs
   - Can process single files, directories, or all components

3. Created comprehensive status tracking (MIGRATION_STATUS.md)
   - Detailed breakdown of completed vs remaining work
   - Function-by-function conversion requirements
   - Effort estimates for each task
   - Clear critical path forward

Files Created/Modified:
- agent_v2.py: POC agent with tools converted (partial, ~600 lines)
- migrate_to_v2.py: Automation script for bulk migration
- MIGRATION_STATUS.md: Current status and remaining work

Remaining Work (~41 hours):
- Convert 5 agent functions in POC (~3 hrs)
- Complete POC orchestration functions (~1.5 hrs)
- POC testing (~2 hrs)
- Apply pattern to 19 remaining agents (~25 hrs)
- Update test infrastructure (~10 hrs)
- Documentation and verification (~6 hrs)

Key Achievement: Validated v2 pattern works for tool conversion.
Next Step: Complete remaining POC agent functions or await decision
on proceeding with full migration vs waiting for v2 stable.
This commit completes the migration of all agent components from Mirascope
v1 to v2, following a systematic test-driven development approach.

## Changes Made

### All Agents (25/25 converted):
- Converted ~100+ @prompt_template decorators to functional prompts
- Updated @llm.call decorator parameters:
  - provider="openai" → provider="openai:completions"
  - model → model_id
  - response_model → format
- Removed all @prompt_template, BaseTool, BaseDynamicConfig imports
- Fixed literal {provider} strings in game agents

### Agents by Complexity:
- 6 simple agents (1 template each)
- 1 medium agent (2 templates)
- 6 standard agents (3 templates each)
- 3 complex agents (4 templates each)
- 6 advanced agents (5 templates each)
- 2 most complex agents (6 templates each)

### Verification:
- 0 @prompt_template decorators remaining
- 15/23 agents import successfully (8 have optional dependencies)
- All conversions follow v2 functional prompt pattern

## Migration Pattern

Functions now return f-strings instead of using decorators.

## Files Modified:
- 25 agent files converted
- Migration status updated

## Next Steps:
- Update test infrastructure for v2 API
- Update documentation
- Run full test suite
## Test Infrastructure Updates

Updated tests/utils/mirascope_test_helpers.py for Mirascope v2 compatibility:

### Changes Made:
- Removed v1-specific imports (BaseMessageParam, BaseToolKit)
- Replaced `assert_uses_prompt_template()` with `assert_returns_prompt_string()`
  for v2 functional prompts
- Updated `assert_has_response_model()` → `assert_has_format_model()`
  to check for `format` parameter
- Updated `assert_provider_agnostic()` → `assert_has_provider_config()`
  to handle v2 provider syntax
- Updated `mock_llm_call()` to use v2 parameters:
  - model → model_id
  - response_model → format_model
  - provider now supports "provider:api_type" syntax
- Updated fixtures for v2 response structure

### Documentation Updates

Updated CLAUDE.md with Mirascope v2 best practices:

- Updated framework version to v2.0.0-alpha.1
- Replaced v1 best practices with v2 patterns:
  - Functional prompts (f-strings) instead of @prompt_template
  - format= instead of response_model=
  - model_id= instead of model=
  - @llm.tool functions instead of BaseTool classes
- Added comprehensive v2 code examples:
  - Basic agent structure with functional prompts
  - Tool implementation with @llm.tool
  - Agent with tools integration

## Impact

All test helpers now support v2 API patterns. Developers can use
updated test utilities to write tests for v2-migrated agents.

Documentation provides clear guidance on v2 patterns for new development.
Document successful migration of all 25 Sygaldry agents from Mirascope v1
to v2.0.0-alpha.1. Report includes:

- Executive summary of completed work
- Detailed scope and statistics (25 agents, ~100+ prompt conversions)
- All key API changes with code examples
- Migration statistics by agent complexity
- Verification results (15/23 agents import successfully)
- Known limitations and recommendations
- Lessons learned and best practices

This completes the Mirascope v2 migration effort.
Reorganize optional dependencies into granular, user-friendly extras that
allow installing only what's needed for specific agents and tools.

Changes:
- Split monolithic 'dev' extras into focused categories:
  * agents: Core Mirascope v2 support (required for any agent)
  * observability: Lilypad SDK (5 agents)
  * async-io: aiofiles (1 agent)
  * search: DuckDuckGo + Exa (9 agents)
  * database: SQLAlchemy + PostgreSQL (3 agents/tools)
  * web: BeautifulSoup + Firecrawl (4 tools)
  * documents: PDF/DOCX/Markdown (3 tools)
  * git: GitPython + PyGithub (1 tool)
  * data: Pandas + JSONPath + YAML (multiple tools)
  * fuzzy: Fuzzy string matching (search tools)
  * youtube: YouTube transcript API (1 tool)
  * all-agents: Meta-package for everything

- Add comprehensive AGENT_DEPENDENCIES.md documentation:
  * Installation guide with examples
  * Detailed requirements for each of 25 agents
  * Requirements for all tools
  * Common installation patterns
  * Troubleshooting guide

- Update MIGRATION_COMPLETE.md with dependency restructuring info

Benefits:
- Users install only what they need (smaller, faster installs)
- Clear separation of concerns
- Better documentation for each agent
- Easier troubleshooting
- No impact on v2 migration compatibility

Examples:
  pip install sygaldry-cli[agents]              # Basic
  pip install sygaldry-cli[agents,search]       # Most common
  pip install sygaldry-cli[all-agents]          # Everything
  pip install sygaldry-cli[dev]                 # Development

Verified:
- TOML syntax valid (14 optional dependency groups)
- Agent imports work correctly
- All dependency counts correct
Comprehensive PR description documenting:
- Complete migration of 25 agents to Mirascope v2
- All key changes and API updates
- Verification results and code quality metrics
- Infrastructure updates (tests, docs, dependencies)
- Files modified and commit history
- Testing status and recommendations
- Migration methodology and lessons learned

Ready for PR creation on GitHub.
@jayscambler jayscambler merged commit f43c5ec into main Nov 12, 2025
1 check passed
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

provider="openai",
model="gpt-4o-mini",
provider="openai:completions",
model_id="gpt-4o-mini",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Recommendations Format Error

The generate_recommendations function is missing the format=list[str] parameter in its @llm.call decorator. Without this parameter, the function returns a raw LLM response object instead of a list[str], causing a type mismatch when the result is assigned to CodeGenerationResponse.recommendations at line 272, which expects list[str].

Fix in Cursor Fix in Web

provider="openai",
model="gpt-4o-mini",
provider="openai:completions",
model_id="gpt-4o-mini",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: LLM Recommendation Format Mismatch

The generate_recommendations function is missing the format=list[str] parameter in its @llm.call decorator. Without this parameter, the function returns a raw LLM response object instead of a list[str], causing a type mismatch when the result is assigned to CodeGenerationResponse.recommendations at line 272, which expects list[str].

Fix in Cursor Fix in Web

personality_prompt: str = PERSONALITY_PROMPTS["balanced"],
provider: str = "openai",
model: str = "gpt-4o",
) -> str:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: LLM Model Customization Feature Broken

The analyze_catan_strategy function (and other game strategy functions in this file) accepts provider and model parameters that are silently ignored because the @llm.call decorator has hardcoded provider="openai:completions" and model_id="gpt-4o-mini". The orchestration code at lines 604-620 retrieves player-specific provider/model preferences and passes them to these functions, expecting them to be used, but they're ignored. This breaks the per-player model configuration feature. The same issue affects develop_trade_proposals, plan_building_action, handle_robber_action, and plan_complete_turn in this file.

Fix in Cursor Fix in Web

personality_prompt: str = PERSONALITY_PROMPTS["balanced"],
provider: str = "openai",
model: str = "gpt-4o",
) -> str:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Strategy functions disregard player model choices.

The analyze_strategic_situation function (and other strategy functions in this file) accepts provider and model parameters that are silently ignored due to hardcoded decorator values. The orchestration code retrieves player-specific preferences and passes them expecting configuration, but they're ignored. This breaks per-player model configuration. The same issue affects develop_negotiation_strategy, craft_diplomatic_messages, plan_military_orders, and synthesize_complete_move in this file.

Fix in Cursor Fix in Web

provider: str = "openai",
model: str = "gpt-4o",
) -> str:
"""Generate DM response to game situation."""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Hardcoded Models Break AI Configuration

The generate_dm_response function (and other DnD functions in this file) accepts provider and model parameters that are silently ignored due to hardcoded decorator values provider="openai:completions" and model_id="gpt-4o-mini". This breaks the expected functionality where different models can be configured for the DM and players. The same issue affects generate_ai_player_action and generate_character_dialogue in this file.

Fix in Cursor Fix in Web

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