Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification on Smolagents #197

Open
harinisri2001 opened this issue Jan 15, 2025 · 2 comments
Open

Clarification on Smolagents #197

harinisri2001 opened this issue Jan 15, 2025 · 2 comments

Comments

@harinisri2001
Copy link

Can someone give a brief description on how CodeAgent is working? In Local where the code is executed? Also can i save/see the AI generated code ?

@touseefahmed96
Copy link

touseefahmed96 commented Jan 15, 2025

The CodeAgent is a specialized agent that extends the MultiStepAgent class. It is designed to generate, parse, and execute code snippets using a language model (LLM). Here's a high-level overview of its workflow:

  1. Initialization of CodeAgent: We first initialize CodeAgent with set of tools that we want our agent to use in order to perform tasks, second, we give a LLM using HfApiModel or any other LLM using LiteLLMModel, we can also provide optional parameters like system prompt, grammar rules, and authorized imports etc. Then the agent sets up a Python executor (LocalPythonInterpreter or E2BExecutor) to run the generated code.
  2. Then LLM generate response, which may include code snippets. The generated code is parsed and executed in (LocalPythonInterpreter or E2BExecutor).
  3. The code generated by the LLM is executed either locally (using LocalPythonInterpreter) or remotely (using E2BExecutor).

Where is the Code Executed Locally?
If use_e2b_executor=False (default), the code is executed locally using the LocalPythonInterpreter. This means the generated code runs in the same Python environment where the CodeAgent is running.
If use_e2b_executor=True, the code is executed remotely using the E2BExecutor.

Can You Save/See the AI-Generated Code?
I am not sure how to save the code but you can view the code in the Agent logs :

agent = CodeAgent(
    tools=[],
    model=HfApiModel(),
)
agent_output = agent.run("print hello word using python")
logs= agent.logs
print(logs)

In the output you can find:

{'role': <MessageRole.ASSISTANT: 'assistant'>, 'content': '[{\'id\': \'call_2\', \'type\': \'function\', \'function\': {\'name\': \'python_interpreter\', \'arguments\': \'print("hello world")\'}}]'}

@aymeric-roucher
Copy link
Collaborator

Take a look at this sneak peek of our upcoming blog post to understand visually how CodeAgent works @harinisri2001 !
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants