Why migrate to Python toolkits?
Python toolkits offer significant advantages over standalone Python tools in production: Performance benefits:- No process overhead: Tools run in a persistent process, eliminating 100-300ms startup time per call
- Shared resources: Tools share dependencies and memory, reducing overall resource usage
- Dedicated containers: In live premium environments, each toolkit gets its own container with 2 vCPUs and 2 GB memory
- Atomic updates: All tools in a toolkit update together, ensuring consistency
- Simplified management: Deploy and manage related tools as a single unit
- Better scaling: Dedicated resources in live environments support higher concurrency
- Tools are called frequently (>10 times per minute)
- You have multiple related tools that share dependencies
- You need better performance in production
- You’ve verified all tools are thread-safe
- Tools use non-thread-safe operations
- Tools are called infrequently
- Tools have conflicting dependencies
- You need independent tool updates
Prerequisites
Before migrating, ensure your tools meet these requirements:1. Thread-safety verification
All tools in a Python toolkit must be thread-safe. Review each tool for: Common thread-safety issues:- Global mutable state
- File system writes
- Non-thread-safe libraries
- Shared database connections without pooling
- Race conditions in shared resources
2. Dependency compatibility
Verify that all tools can use the same dependency versions:3. Shared utility functions
Identify common code that can be shared:- Authentication helpers
- Data transformation utilities
- API client wrappers
- Validation functions
Migration process
Step 1: Identify candidate tools
List all standalone Python tools and group them by: Functional relationship:- Tools that work with the same API or service
- Tools that perform related operations
- Tools that share business logic
- Frequently called tools (>10 calls/minute)
- Tools called together by the same agents
- Tools with similar performance requirements
Step 2: Create toolkit folder structure
Organize your tools into a toolkit folder:- Use descriptive folder names (e.g.,
customer_service_toolkit) - Keep one tool per file for clarity
- Place shared code in
utils/or__init__.py - Include comprehensive
requirements.txt
Step 3: Consolidate dependencies
Mergerequirements.txt files from all tools:
Step 4: Refactor tool code
Update each tool file to work in a toolkit context: Before (standalone tool):- Use
async deffor all tool functions - Use async libraries (
httpxinstead ofrequests) - Remove global mutable state
- Use proper async patterns
Step 5: Extract shared utilities
Move common code to shared modules: Before (duplicated code):Step 6: Update tool names
When you import a toolkit, tool names change to include the toolkit prefix: Naming convention:Step 7: Import the toolkit
Import your toolkit using the ADK CLI:Step 8: Update agent configurations
Update all agents that use the migrated tools: Before (standalone tools):Step 9: Test in draft environment
Thoroughly test the toolkit before deploying to live: Functional testing:Step 10: Deploy to live environment
After successful testing in draft:- Check response times
- Monitor error rates
- Verify concurrent request handling
- Review resource usage
Step 11: Remove old standalone tools
After confirming the toolkit works correctly:- All agents are updated and tested
- Toolkit is deployed to live
- No agents reference the old tool names
Common migration patterns
Pattern 1: Simple consolidation
Scenario: Multiple independent tools with no shared code Before:- Create toolkit folder
- Move tool files
- Consolidate requirements.txt
- Import as toolkit
Pattern 2: Shared utilities extraction
Scenario: Tools with duplicated helper functions Before:- Identify duplicated code
- Extract to shared module
- Update imports in all tools
- Test thoroughly
Pattern 3: Multi-file tool consolidation
Scenario: Standalone tools with package roots Before:- Create toolkit folder
- Move each tool into subfolder
- Consolidate requirements.txt
- Update relative imports if needed
Handling special cases
Non-thread-safe tools
If a tool cannot be made thread-safe: Option 1: Keep as standalone toolConflicting dependencies
If tools require different versions: Option 1: Separate toolkitsConnection remapping
If tools use different connection names:Validation checklist
Before deploying to production, verify:- All tools are thread-safe
- Dependencies are consolidated and pinned
- Shared utilities are extracted
- Tool names are documented
- Agent configurations are updated
- Tests pass in draft environment
- Concurrency tests pass
- Performance meets expectations
- Error handling is robust
- Logging is adequate
- Documentation is updated
- Rollback plan is ready

