Code assistant
Writes a program, runs it, and reports what it saw rather than what it expected.
The program, and what it printed
This ran against effGen with gemini:gemini-3.1-flash-lite. The pane under the code is that run’s output, pasted — so where the answer depends on a live API or on the model’s wording, yours will differ. The pane is the shape that run actually had, not a tidied one.
from effgen import Agent, AgentConfig
from effgen.tools.builtin import CodeExecutor, PythonREPL
agent = Agent(AgentConfig(
model="gemini:gemini-3.1-flash-lite",
name="code-assistant",
system_prompt=(
"You are a coding assistant. Write the code, run it with a tool, "
"read the output, and report the result you actually saw."
),
tools=[PythonREPL(), CodeExecutor()],
max_iterations=8,
))
response = agent.run(
"Write a Python function that returns the longest palindromic substring "
"of a string, run it on 'forgeeksskeegfor', and report what it printed."
)
print(response.text)
print()
for call in response.tool_calls:
print(f" {call.name} -> {'error' if call.error else 'ok'}")geeksskeeg code_executor -> ok
What it does
The point of a coding agent is not that it writes code — it is that it runs the code before telling you it works. This agent has two execution tools and an iteration budget: it writes a function, executes it on a real input, reads the output, and answers with what came back. If the code raises, it sees the traceback and tries again.
What the run shows
- The answer is the string the executed program printed, not the model's prediction of it.
- response.tool_calls carries every call the run made, including the ones that failed, so you can see which path the agent took.
- CodeExecutor runs in a sandbox: a container where one is available, and an unprivileged subprocess namespace otherwise. Code that exits non-zero returns success=False with the reason.
The full script
The program above is the short version. The one in the repository at examples/tools/coding_agent.py covers more cases and takes a --model flag. It ships with the package, so it runs from the command line without cloning anything:
effgen examples run tools/coding_agentRead it on GitHub