{"id":30533749,"url":"https://github.com/yepcode/ag2-ext-yepcode","last_synced_at":"2025-10-09T03:14:50.969Z","repository":{"id":310640419,"uuid":"1016066411","full_name":"yepcode/ag2-ext-yepcode","owner":"yepcode","description":"Enables AG2 (formerly Autogen) agents to securely execute code in isolated remote sandboxes using YepCode’s serverless runtime.","archived":false,"fork":false,"pushed_at":"2025-09-30T09:08:01.000Z","size":511,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-30T11:24:05.955Z","etag":null,"topics":["ag2","ag2-extension","ag2-sample","autogen","autogen-extension","autogen-sample"],"latest_commit_sha":null,"homepage":"https://yepcode.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yepcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-08T12:45:52.000Z","updated_at":"2025-09-30T09:08:05.000Z","dependencies_parsed_at":"2025-08-21T21:31:59.605Z","dependency_job_id":null,"html_url":"https://github.com/yepcode/ag2-ext-yepcode","commit_stats":null,"previous_names":["yepcode/ag2-ext-yepcode"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yepcode/ag2-ext-yepcode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yepcode%2Fag2-ext-yepcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yepcode%2Fag2-ext-yepcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yepcode%2Fag2-ext-yepcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yepcode%2Fag2-ext-yepcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yepcode","download_url":"https://codeload.github.com/yepcode/ag2-ext-yepcode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yepcode%2Fag2-ext-yepcode/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000773,"owners_count":26082911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ag2","ag2-extension","ag2-sample","autogen","autogen-extension","autogen-sample"],"created_at":"2025-08-27T12:49:23.089Z","updated_at":"2025-10-09T03:14:50.964Z","avatar_url":"https://github.com/yepcode.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![YepCode Run SDK Preview](https://yepcode.io/images/cover/yepcode-ultimate-dev-tool-ai-solutions.png)\n\n\u003cdiv align=\"center\"\u003e\n\n[![PyPI Version](https://img.shields.io/pypi/v/ag2-ext-yepcode)](https://pypi.org/project/ag2-ext-yepcode/)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/ag2-ext-yepcode)](https://pypi.org/project/ag2-ext-yepcode/)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/yepcode/ag2-ext-yepcode-py/ci.yml)](https://github.com/yepcode/ag2-ext-yepcode-py/actions)\n\n\u003c/div\u003e\n\n# AG2 Extension for YepCode\n\nAn [AG2](https://ag2.ai/) (formerly AutoGen) extension that enables secure code execution using [YepCode's](https://yepcode.io/l/J80qg) serverless runtime environment. Execute Python and JavaScript code in production-grade, isolated sandboxes with built-in security and scalability.\n\n\u003e **Note**: AG2 was evolved from AutoGen. If you are looking for the extension for AutoGen, please check the [autogen-ext-yepcode](https://github.com/yepcode/autogen-ext-yepcode) repository.\n\n## Features\n\n- **Secure Execution**: Code runs in isolated, production-grade sandboxes\n- **Multi-language Support**: Python and JavaScript execution\n- **Automatic Package Installation**: YepCode automatically detects and installs dependencies in the sandbox\n- **Logging and Monitoring**: Access to YepCode's execution logs, results and errors\n- **AG2 Integration**: Seamless integration with AG2 agents and tools\n\n## Installation\n\nInstall the package using pip:\n\n```bash\npip install ag2_ext_yepcode\n```\n\n## Setup\n\n1. **Create a YepCode Account**: Sign up at [yepcode.io](https://yepcode.io/l/J80qg)\n2. **Get Your API Token**: Navigate to `Settings` \u003e `API credentials` in your YepCode workspace\n3. **Set Environment Variable**:\n\n   ```bash\n   export YEPCODE_API_TOKEN=\"your-api-token-here\"\n   ```\n\nAlternatively, you can pass the API token directly to the executor constructor.\n\n## Quick Start\n\n### Basic Integration with AG2\n\nThe YepCode executor is designed to work with AG2 agents as a `CodeExecutor`. Here's a example of just the code executor agent:\n\n```python\nfrom autogen import ConversableAgent, LLMConfig\nfrom ag2_ext_yepcode import YepCodeCodeExecutor\nfrom dotenv import load_dotenv\nimport os\n\n# Load environment variables from .env file if it exists\nload_dotenv()\n\n# Initialize YepCode executor\nyepcode_executor = YepCodeCodeExecutor(\n    timeout=120,\n    remove_on_done=False,\n    sync_execution=True,\n)\n\n# Create an agent with code executor configuration.\ncode_executor_agent = ConversableAgent(\n    \"code_executor_agent\",\n    llm_config=False,  # Turn off LLM for this agent.\n    code_execution_config={\n        \"executor\": yepcode_executor\n    },  # Use the local command line code executor.\n    human_input_mode=\"ALWAYS\",  # Always take human input for this agent for safety.\n)\n\ntask = \"\"\"Run this code:\n\\```python\nmessage = \"Hello, world!\"\nprint(message)\nreturn message\n\\```\n\nand return the output.\n\"\"\"\n\n# Generate a reply for the given code.\nreply = code_executor_agent.generate_reply(messages=[{\"role\": \"user\", \"content\": task}])\nprint(reply)\n```\n\n### With LLMs and code execution tools\n\nThe extension also works with more advanced patterns, like using LLMs and code execution tools:\n\n```python\nfrom autogen import ConversableAgent, LLMConfig\nfrom ag2_ext_yepcode import YepCodeCodeExecutor\nfrom dotenv import load_dotenv\nimport os\n\n# Load environment variables from .env file if it exists\nload_dotenv()\n\n# Initialize YepCode executor\nyepcode_executor = YepCodeCodeExecutor(\n    timeout=120,\n    remove_on_done=False,\n    sync_execution=True,\n)\n\n# Create an agent with code executor configuration.\ncode_executor_agent = ConversableAgent(\n    \"code_executor_agent\",\n    llm_config=False,  # Turn off LLM for this agent.\n    code_execution_config={\n        \"executor\": yepcode_executor\n    },  # Use the local command line code executor.\n    human_input_mode=\"ALWAYS\",\n)\n\n# The code writer agent's system message is to instruct the LLM on how to use\n# the code executor in the code executor agent.\ncode_writer_system_message = \"\"\"You are a helpful AI assistant.\nSolve tasks using your coding and language skills.\nIn the following cases, suggest python code (in a python coding block) for the user to execute.\n1. When you need to collect info, use the code to output the info you need. After sufficient info is printed and the task is ready to be solved based on your language skill, you can solve the task by yourself.\n2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly.\nSolve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill.\nWhen using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can't modify your code. So do not suggest incomplete code which requires users to modify. Don't use a code block if it's not intended to be executed by the user.\nIf the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try.\nWhen you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible.\nReply 'TERMINATE' in the end when everything is done.\n\"\"\"\n\ncode_writer_agent = ConversableAgent(\n    \"code_writer_agent\",\n    system_message=code_writer_system_message,\n    llm_config=LLMConfig(\n        api_type=\"anthropic\",\n        model=\"claude-3-haiku-20240307\",\n        api_key=os.environ[\"ANTHROPIC_API_KEY\"],\n    ),\n    code_execution_config=False,  # Turn off code execution for this agent.\n)\n\nchat_result = code_executor_agent.initiate_chat(\n    code_writer_agent,\n    message=\"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.\",\n)\nprint(chat_result)\n```\n\n### Custom Configuration\n\nYou can customize the YepCode executor behavior:\n\n```python\n# Custom executor configuration\nyepcode_executor = YepCodeCodeExecutor(\n    api_token=\"your-api-token\",  # Optional: pass token directly\n    timeout=300,  # 5 minutes timeout\n    remove_on_done=False,  # Keep execution records for debugging\n    sync_execution=True,  # Wait for completion\n)\n```\n\n## API Reference\n\n### YepCodeCodeExecutor\n\nThe main executor class for running code in YepCode's serverless environment.\n\n#### Constructor Parameters\n\n- `api_token` (Optional[str]): YepCode API token. If not provided, will use `YEPCODE_API_TOKEN` environment variable.\n- `timeout` (int): Execution timeout in seconds. Default: 60.\n- `remove_on_done` (bool): Whether to remove execution records after completion. Default: True.\n- `sync_execution` (bool): Whether to wait for execution completion. Default: True.\n\n#### Methods\n\n- `async execute_code_blocks(code_blocks, cancellation_token)`: Execute code blocks\n\n### YepCodeCodeResult\n\nResult object returned from code execution.\n\n#### Properties\n\n- `exit_code` (int): Execution exit code (0 for success)\n- `output` (str): Execution output and logs\n- `execution_id` (Optional[str]): YepCode execution ID for tracking\n\n## Supported Languages\n\n| Language   | Language Code | Aliases |\n| ---------- | ------------- | ------- |\n| Python     | `python`      | `py`    |\n| JavaScript | `javascript`  | `js`    |\n\n## Development\n\n### Setup Development Environment\n\n```bash\ngit clone https://github.com/yepcode/ag2_ext_yepcode.git\ncd ag2_ext_yepcode\npoetry install\n```\n\n### Run Tests\n\n```bash\npytest tests/ -v\n```\n\n## 📚 Documentation\n\n- **[YepCode Documentation](https://yepcode.io/docs)**: Complete YepCode platform documentation\n- **[AG2 Documentation](https://docs.ag2.ai/)**: AG2 framework documentation\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyepcode%2Fag2-ext-yepcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyepcode%2Fag2-ext-yepcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyepcode%2Fag2-ext-yepcode/lists"}