Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enables Autogen agents to securely execute code in isolated remote sandboxes using YepCode’s serverless runtime.

License

NotificationsYou must be signed in to change notification settings

yepcode/autogen-ext-yepcode

Repository files navigation

YepCode Run SDK Preview

PyPI VersionPyPI DownloadsGitHub Workflow Status

AutoGen Extension for YepCode

AnAutoGen extension that enables secure code execution usingYepCode's serverless runtime environment. Execute Python and JavaScript code in production-grade, isolated sandboxes with built-in security and scalability.

Note: If you are looking for the extension for AG2, which was evolved from AutoGen, please check theautogen-ext-yepcode repository.

Features

  • Secure Execution: Code runs in isolated, production-grade sandboxes
  • Multi-language Support: Python and JavaScript execution
  • Automatic Package Installation: YepCode automatically detects and installs dependencies in the sandbox
  • Logging and Monitoring: Access to YepCode's execution logs, results and errors
  • AutoGen Integration: Seamless integration with AutoGen agents and tools

Installation

Install the package using pip:

pip install autogen_ext_yepcode

Setup

  1. Create a YepCode Account: Sign up atyepcode.io

  2. Get Your API Token: Navigate toSettings >API credentials in your YepCode workspace

  3. Set Environment Variable:

    export YEPCODE_API_TOKEN="your-api-token-here"

Alternatively, you can pass the API token directly to the executor constructor.

Quick Start

Basic Integration with AutoGen

The YepCode executor is designed to work with AutoGen agents through thePythonCodeExecutionTool. Here's a complete example:

importasyncioimportosfromautogen_agentchat.agentsimportAssistantAgentfromautogen_ext.models.openaiimportOpenAIChatCompletionClientfromautogen_ext.tools.code_executionimportPythonCodeExecutionToolfromautogen_ext_yepcodeimportYepCodeCodeExecutorasyncdefmain():# Create OpenAI model clientmodel_client=OpenAIChatCompletionClient(model="gpt-4",api_key=os.getenv("OPENAI_API_KEY"),    )# Initialize YepCode executoryepcode_executor=YepCodeCodeExecutor(timeout=120,remove_on_done=False,sync_execution=True,    )# Start the executorawaityepcode_executor.start()# Create a PythonCodeExecutionTool with the YepCode executorcode_tool=PythonCodeExecutionTool(executor=yepcode_executor)# Create an AssistantAgent with the code execution toolassistant=AssistantAgent(name="assistant",model_client=model_client,tools=[code_tool],    )# Run a task that requires code executiontask="Calculate the sum of squares for numbers 1 to 10. Show the calculation step by step using Python code."result=awaitassistant.run(task=task)print(f"Result:{result}")# Clean upawaityepcode_executor.stop()awaitmodel_client.close()if__name__=="__main__":asyncio.run(main())

With Anthropic Claude

The extension also works with other model providers like Anthropic:

importasyncioimportosfromautogen_agentchat.agentsimportAssistantAgentfromautogen_ext.models.anthropicimportAnthropicChatCompletionClientfromautogen_ext.tools.code_executionimportPythonCodeExecutionToolfromautogen_ext_yepcodeimportYepCodeCodeExecutorasyncdefmain():# Create Anthropic model clientmodel_client=AnthropicChatCompletionClient(model="claude-3-haiku-20240307",api_key=os.getenv("ANTHROPIC_API_KEY"),    )# Initialize YepCode executoryepcode_executor=YepCodeCodeExecutor(timeout=120,remove_on_done=False,sync_execution=True,    )# Start the executorawaityepcode_executor.start()# Create a PythonCodeExecutionTool with the YepCode executorcode_tool=PythonCodeExecutionTool(executor=yepcode_executor)# Create an AssistantAgentassistant=AssistantAgent(name="assistant",model_client=model_client,tools=[code_tool],    )# Run a tasktask="Fetch cryptocurrency price data from a public API and analyze the top 5 cryptocurrencies by market cap. Use the requests library to get data and calculate some basic statistics."result=awaitassistant.run(task=task)print(f"Result:{result}")# Clean upawaityepcode_executor.stop()awaitmodel_client.close()if__name__=="__main__":asyncio.run(main())

Custom Configuration

You can customize the YepCode executor behavior:

# Custom executor configurationyepcode_executor=YepCodeCodeExecutor(api_token="your-api-token",# Optional: pass token directlytimeout=300,# 5 minutes timeoutremove_on_done=False,# Keep execution records for debuggingsync_execution=True,# Wait for completion)

Usage Patterns

Standard AutoGen Pattern

The recommended approach is to use theYepCodeCodeExecutor with AutoGen'sPythonCodeExecutionTool:

# 1. Create the YepCode executoryepcode_executor=YepCodeCodeExecutor()awaityepcode_executor.start()# 2. Wrap it in a PythonCodeExecutionToolcode_tool=PythonCodeExecutionTool(executor=yepcode_executor)# 3. Add to your AssistantAgentassistant=AssistantAgent(name="assistant",model_client=your_model_client,tools=[code_tool],)# 4. Use normally with AutoGenresult=awaitassistant.run("Your task here")

Context Manager Pattern

You can also use the executor as a context manager:

asyncdefmain():asyncwithYepCodeCodeExecutor()asexecutor:code_tool=PythonCodeExecutionTool(executor=executor)# Use the tool with your agentsassistant=AssistantAgent(name="assistant",model_client=model_client,tools=[code_tool],        )result=awaitassistant.run("Your task")

API Reference

YepCodeCodeExecutor

The main executor class for running code in YepCode's serverless environment.

Constructor Parameters

  • api_token (Optional[str]): YepCode API token. If not provided, will useYEPCODE_API_TOKEN environment variable.
  • timeout (int): Execution timeout in seconds. Default: 60.
  • remove_on_done (bool): Whether to remove execution records after completion. Default: True.
  • sync_execution (bool): Whether to wait for execution completion. Default: True.

Methods

  • async start(): Initialize the executor
  • async stop(): Clean up the executor
  • async execute_code_blocks(code_blocks, cancellation_token): Execute code blocks
  • async restart(): Restart the executor

YepCodeCodeResult

Result object returned from code execution.

Properties

  • exit_code (int): Execution exit code (0 for success)
  • output (str): Execution output and logs
  • execution_id (Optional[str]): YepCode execution ID for tracking

Supported Languages

LanguageLanguage CodeAliases
Pythonpythonpy
JavaScriptjavascriptjs

Examples

Check out thesamples directory for comprehensive examples:

Development

Setup Development Environment

git clone https://github.com/yepcode/autogen_ext_yepcode.gitcd autogen_ext_yepcodepoetry install

Run Tests

pytest tests/ -v

📚 Documentation

License

This project is licensed under the MIT License - see theLICENSE file for details.

About

Enables Autogen agents to securely execute code in isolated remote sandboxes using YepCode’s serverless runtime.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp