RAG Agent GitHub Repository
Import Required Packages
Initialize Composio Toolset
Set up the AI Model
Create the AI Agent
Set up the Agent Executor
Define the Code Execution Function
Run the Code Execution Agent
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
The project generates and executes code based on user-defined problems. It utilizes the Composio and connects your AI Agent to E2B’s Code Interpreter to facilitate code execution, allowing users to input a problem statement and receive executable code as output. The agent is designed to operate in a sandbox environment, ensuring safe execution and accurate results. Key functionalities include code generation, execution, and result interpretation, making it an invaluable resource for developers and data scientists alike.
Import Required Packages
import os
from composio_langchain import Action, App, ComposioToolSet
from crewai import Agent, Crew, Process, Task
Initialize Composio Toolset
composio_toolset = ComposioToolSet()
tools = composio_toolset.get_tools(apps=[App.CODEINTERPRETER])
Set up the AI Model
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")
Create the AI Agent
python_executor_agent = Agent(
role="Python Code Executor",
goal="Execute Python code in a Jupyter notebook cell and return the results.",
verbose=True,
memory=True,
backstory="You are an expert in executing Python code and interpreting results in a sandbox environment.",
allow_delegation=False,
tools=tools,
)
Set up the Agent Executor
python_code = """
def calculate_sum(a, b):
return a + b
result = calculate_sum(5, 3)
print(result)
"""
execute_code_task = Task(
description="Execute the following Python code and return the results:\n\n"
+ python_code,
expected_output="Execution of Python code returned the results.",
tools=tools,
agent=python_executor_agent,
allow_delegation=False,
)
Define the Code Execution Function
crew = Crew(
agents=[python_executor_agent],
tasks=[execute_code_task],
process=Process.sequential,
)
Run the Code Execution Agent
result = crew.kickoff()
print(result)
import os
from composio_langchain import Action, App, ComposioToolSet
from crewai import Agent, Crew, Process, Task
toolset = ComposioToolSet()
tools = toolset.get_tools(apps=[App.CODEINTERPRETER])
python_executor_agent = Agent(
role="Python Code Executor",
goal="Execute Python code in a Jupyter notebook cell and return the results.",
verbose=True,
memory=True,
backstory="You are an expert in executing Python code and interpreting results in a sandbox environment.",
allow_delegation=False,
tools=tools,
)
python_code = """
def calculate_sum(a, b):
return a + b
result = calculate_sum(5, 3)
print(result)
"""
execute_code_task = Task(
description="Execute the following Python code and return the results:\n\n"
+ python_code,
expected_output="Execution of Python code returned the results.",
tools=tools,
agent=python_executor_agent,
allow_delegation=False,
)
crew = Crew(
agents=[python_executor_agent],
tasks=[execute_code_task],
process=Process.sequential,
)
result = crew.kickoff()
print(result)
Was this page helpful?