View Source Code
Check out the full source code for this example on GitHub.
Overview
The Code Interpreter Agent follows this workflow:- User Request: The user asks a question that requires code execution (e.g., “Calculate the Fibonacci sequence up to 100”).
- Code Generation: An OpenAI agent interprets the request and generates the necessary Python code.
- Secure Execution: The code is sent to a Tensorlake function running in a secure, isolated container.
- Result Retrieval: The execution output (stdout, stderr) is captured and returned to the agent.
- Final Answer: The agent formulates a final response based on the code output.
Prerequisites
- Python 3.11+
- Tensorlake Account and CLI installed.
- OpenAI API Key
Implementation (app.py)
Here is the complete implementation for the Code Interpreter Agent.
Running Locally
To test the interpreter locally, add this code block to the end ofapp.py: