# How can i get the variable in CodeAgent in smolagent

**URL:** <https://discuss.huggingface.co/t/how-can-i-get-the-variable-in-codeagent-in-smolagent/142997>\
**Category:** Beginners\
**Created:** [February 26, 2025, 7:17am UTC](https://discuss.huggingface.co/t/how-can-i-get-the-variable-in-codeagent-in-smolagent/142997 "2025-02-26T07:17:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![which47](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@which47](https://discuss.huggingface.co/u/which47)\
**Post date:** [February 26, 2025, 7:17am UTC](https://discuss.huggingface.co/t/how-can-i-get-the-variable-in-codeagent-in-smolagent/142997/1 "2025-02-26T07:17:25Z")

</div>

If the Python Interpreter runs the code, Can I get the variable in the CodeAgent object?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 26, 2025, 3:17pm UTC](https://discuss.huggingface.co/t/how-can-i-get-the-variable-in-codeagent-in-smolagent/142997/2 "2025-02-26T15:17:29Z")

</div>

I don’t think there is a method for extracting variables at the moment.

> <https://github.com/huggingface/smolagents/issues/322>
>
> When we run a CodeAgent in a notebook, it print the question/task, the LLM model… used, code (Executing this code, Execution logs) and the Final answer. 
> 
> The return value from agent.run contrains only the final response. 
> 
> I'm working on some demos for which I wanted to run a number of tasks, capture all the output (not just the final answer) and write them to an md or html file, so that I can show everything including the code generated by the agent without running the agents live in the demo. 
> 
> I tried logging, stdout, from contextlib import redirect\_stdout, etc but couldn't capture the full output to a variable. 
> 
> Thanks,
