Python implementation of the Code-Mode library for UTCP (Universal Tool Calling Protocol).
pip install code-modefrom code_mode import CodeModeClient
# Initialize the client
client = CodeModeClient.create()
# Register tools (example with mock manual)
await client.register_manual({
'name': 'github',
'call_template_type': 'http',
'config': {
'base_url': 'https://api.github.com'
}
})
# Execute Python code with tool access
result = await client.call_tool_chain("""
# Call tools and process data
pr = await github.get_pull_request(owner='microsoft', repo='vscode', pull_number=1234)
comments = await github.get_pull_request_comments(owner='microsoft', repo='vscode', pull_number=1234)
# Return processed result
return {
'title': pr['title'],
'comment_count': len(comments)
}
""")
print(result['result']) # Access the execution result
print(result['logs']) # Access console output- Python Code Execution: Execute Python code with access to registered UTCP tools
- Tool Integration: Seamlessly call tools as Python functions
- Console Logging: Automatic capture of print statements and logging
- Timeout Protection: Configurable execution timeouts
- Type Hints: Full type hint support for better IDE integration
Create a new CodeModeClient instance.
Register a UTCP manual with tools.
Execute Python code with tool access. Returns dict with 'result' and 'logs'.
Get Python interface definitions for all registered tools.
MPL-2.0