Skip to main content
This guide helps you migrate existing standalone Python tools into Python toolkits for improved performance and resource efficiency in production environments.

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
Operational benefits:
  • 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
When to migrate:
  • 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
When NOT to migrate:
  • Tools use non-thread-safe operations
  • Tools are called infrequently
  • Tools have conflicting dependencies
  • You need independent tool updates
For help deciding, see Choosing a tool type.

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
Testing for thread-safety:

2. Dependency compatibility

Verify that all tools can use the same dependency versions:
If tools require different versions of the same package, they cannot be in the same toolkit.

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
Usage patterns:
  • Frequently called tools (>10 calls/minute)
  • Tools called together by the same agents
  • Tools with similar performance requirements
Example grouping:

Step 2: Create toolkit folder structure

Organize your tools into a toolkit folder:
Best practices:
  • 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

Merge requirements.txt files from all tools:
Resolve version conflicts:
Pin all dependencies:

Step 4: Refactor tool code

Update each tool file to work in a toolkit context: Before (standalone tool):
After (toolkit tool):
Key changes:
  1. Use async def for all tool functions
  2. Use async libraries (httpx instead of requests)
  3. Remove global mutable state
  4. Use proper async patterns

Step 5: Extract shared utilities

Move common code to shared modules: Before (duplicated code):
After (shared utilities):

Step 6: Update tool names

When you import a toolkit, tool names change to include the toolkit prefix: Naming convention:
Example:
Document the name changes:

Step 7: Import the toolkit

Import your toolkit using the ADK CLI:
Verify import:
Expected output:

Step 8: Update agent configurations

Update all agents that use the migrated tools: Before (standalone tools):
After (toolkit tools):
Update and redeploy agents:

Step 9: Test in draft environment

Thoroughly test the toolkit before deploying to live: Functional testing:
Concurrency testing:
Performance testing:
Compare with standalone tool performance to verify improvement.

Step 10: Deploy to live environment

After successful testing in draft:
Monitor performance:
  • 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:
Important: Only remove standalone tools after:
  1. All agents are updated and tested
  2. Toolkit is deployed to live
  3. No agents reference the old tool names

Common migration patterns

Pattern 1: Simple consolidation

Scenario: Multiple independent tools with no shared code Before:
After:
Steps:
  1. Create toolkit folder
  2. Move tool files
  3. Consolidate requirements.txt
  4. Import as toolkit

Pattern 2: Shared utilities extraction

Scenario: Tools with duplicated helper functions Before:
After:
Steps:
  1. Identify duplicated code
  2. Extract to shared module
  3. Update imports in all tools
  4. Test thoroughly

Pattern 3: Multi-file tool consolidation

Scenario: Standalone tools with package roots Before:
After:
Steps:
  1. Create toolkit folder
  2. Move each tool into subfolder
  3. Consolidate requirements.txt
  4. 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 tool
Option 2: Add synchronization

Conflicting dependencies

If tools require different versions: Option 1: Separate toolkits
Option 2: Update to compatible versions

Connection 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

Rollback procedure

If issues occur after migration:

Immediate rollback

Gradual rollback

Performance optimization

After migration, optimize toolkit performance:

1. Connection pooling

2. Caching

3. Async patterns

Monitoring and troubleshooting

Monitor toolkit health

Common issues

Issue: Tools timing out
Issue: Memory errors
Issue: Race conditions

Next steps