Skip to content

System prompt

Default templates

freeact uses default system prompt templates for instructing models to generate code actions:

  • CODE_TAG_SYSTEM_TEMPLATE instructs a model to include code actions directly in the response text, enclosed in <code-action> tags.
  • TOOL_USE_SYSTEM_TEMPLATE instructs a model to use an execute_ipython_cell tool and pass code actions as code argument.

These are chosen by freeact based on the use_executor_tool argument of the LiteCodeActModel constructor, or the model name and provider if use_executor_tool=None.

Tip

Default templates cover only generic agent behavior. To adapt an agent to application- and domain-specific requirements, it can be useful to provide custom system templates.

Custom templates

The following example uses a custom system template that extends the default system template (diff) with instructions for the agent to:

  • create and share a plan before acting
  • asking the user for feedback on the plan
  • adjust the plan if necessary
  • suggest 3 follow-up queries after the final response
examples/custom.py
import asyncio
import os

from rich.console import Console

from examples.custom_template import TOOL_USE_SYSTEM_TEMPLATE as CUSTOM_TEMPLATE
from freeact import CodeActAgent, LiteCodeActModel, execution_environment
from freeact.cli.utils import stream_conversation


async def main():
    async with execution_environment(
        ipybox_tag="ghcr.io/gradion-ai/ipybox:basic",
        ipybox_env={"GEMINI_API_KEY": os.environ["GEMINI_API_KEY"]},
    ) as env:
        async with env.code_provider() as provider:
            skill_sources = await provider.get_sources(
                module_names=["freeact_skills.search.google.stream.api"],
            )
        async with env.code_executor() as executor:
            model = LiteCodeActModel(
                model_name="anthropic/claude-3-7-sonnet-20250219",
                reasoning_effort="low",
                skill_sources=skill_sources,
                system_template=CUSTOM_TEMPLATE,  # (1)!
                use_executor_tool=True,  # (2)!
                api_key=os.environ["ANTHROPIC_API_KEY"],
            )
            agent = CodeActAgent(model=model, executor=executor)
            await stream_conversation(agent, console=Console())


if __name__ == "__main__":
    asyncio.run(main())
  1. Configures the code action model with the custom system template.

  2. This is the default for anthropic/claude-3-7-sonnet-20250219 but added here for clarity.

curl -o custom_template.txt https://raw.githubusercontent.com/gradion-ai/freeact/refs/heads/main/examples/template.txt
uvx freeact \
  --ipybox-tag=ghcr.io/gradion-ai/ipybox:example \
  --model-name=anthropic/claude-3-7-sonnet-20250219 \
  --reasoning-effort=low \
  --system-template=custom_template.txt \
  --api-key=$ANTHROPIC_API_KEY

Example

output