# freeact
<p align="left">
<a href="https://gradion-ai.github.io/freeact/"><img alt="Website" src="https://img.shields.io/website?url=https%3A%2F%2Fgradion-ai.github.io%2Ffreeact%2F&up_message=online&down_message=offline&label=docs"></a>
<a href="https://pypi.org/project/freeact/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/freeact?color=blue"></a>
<a href="https://github.com/gradion-ai/freeact/releases"><img alt="GitHub Release" src="https://img.shields.io/github/v/release/gradion-ai/freeact"></a>
<a href="https://github.com/gradion-ai/freeact/actions"><img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/gradion-ai/freeact/test.yml"></a>
<a href="https://github.com/gradion-ai/freeact/blob/main/LICENSE"><img alt="GitHub License" src="https://img.shields.io/github/license/gradion-ai/freeact?color=blueviolet"></a>
<a href="https://pypi.org/project/freeact/"><img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/freeact"></a>
</p>
A lightweight library for code-action based agents.
- [Introduction](#introduction)
- [Key capabilities](#key-capabilities)
- [Quickstart](#quickstart)
- [Evaluation](#evaluation)
- [Supported models](https://gradion-ai.github.io/freeact/models/)
## Introduction
`freeact` is a lightweight agent library that empowers language models to act as autonomous agents through executable **code actions**. By enabling agents to express their actions directly in code rather than through constrained formats like JSON, `freeact` provides a flexible and powerful approach to solving complex, open-ended problems that require dynamic solution paths.
The library builds upon [recent](https://arxiv.org/abs/2402.01030) [research](https://arxiv.org/abs/2411.01747) demonstrating that code-based actions significantly outperform traditional agent approaches, with studies showing up to 20% higher success rates compared to conventional methods. While existing solutions often restrict agents to predefined tool sets, `freeact` removes these limitations by allowing agents to leverage the full power of the Python ecosystem, dynamically installing and utilizing any required libraries as needed.
## Key capabilities
`freeact` agents can autonomously improve their actions through learning from environmental feedback, execution results, and human guidance. They can store and reuse successful code actions as custom skills in long-term memory. These skills can be composed and interactively refined to build increasingly sophisticated capabilities, enabling efficient scaling to complex tasks.
`freeact` executes all code actions within [`ipybox`](https://gradion-ai.github.io/ipybox/), a secure execution environment built on IPython and Docker that can also be deployed locally. This ensures safe execution of dynamically generated code while maintaining full access to the Python ecosystem. Combined with its lightweight and extensible architecture, `freeact` provides a robust foundation for building adaptable AI agents that can resolve real-world challenges requiring dynamic problem-solving approaches.
## Quickstart
Install `freeact` using pip:
```bash
pip install freeact
```
Create a `.env` file with [Anthropic](https://console.anthropic.com/settings/keys) and [Gemini](https://aistudio.google.com/app/apikey) API keys:
```env title=".env"
# Required for Claude 3.5 Sonnet
ANTHROPIC_API_KEY=...
# Required for generative Google Search via Gemini 2
GOOGLE_API_KEY=...
```
Launch a `freeact` agent with generative Google Search skill using the [CLI](https://gradion-ai.github.io/freeact/cli/):
```bash
python -m freeact.cli \
--model-name=anthropic/claude-3-5-sonnet-20241022 \
--ipybox-tag=ghcr.io/gradion-ai/ipybox:basic \
--skill-modules=freeact_skills.search.google.stream.api
```
or an equivalent [quickstart.py](examples/quickstart.py) script:
```python
import asyncio
from rich.console import Console
from freeact import Claude, CodeActAgent, execution_environment
from freeact.cli.utils import stream_conversation
async def main():
async with execution_environment(
ipybox_tag="ghcr.io/gradion-ai/ipybox:basic",
) as env:
skill_sources = await env.executor.get_module_sources(
module_names=["freeact_skills.search.google.stream.api"],
)
model = Claude(model_name="anthropic/claude-3-5-sonnet-20241022")
agent = CodeActAgent(model=model, executor=env.executor)
await stream_conversation(agent, console=Console(), skill_sources=skill_sources)
if __name__ == "__main__":
asyncio.run(main())
```
Once launched, you can start interacting with the agent:
https://github.com/user-attachments/assets/83cec179-54dc-456c-b647-ea98ec99600b
## Evaluation
We [evaluated](evaluation) `freeact` with the following models:
- Claude 3.5 Sonnet (`claude-3-5-sonnet-20241022`)
- Claude 3.5 Haiku (`claude-3-5-haiku-20241022`)
- Gemini 2.0 Flash (`gemini-2.0-flash-exp`)
- Qwen 2.5 Coder 32B Instruct (`qwen2p5-coder-32b-instruct`)
- DeepSeek V3 (`deepseek-v3`)
- DeepSeek R1 (`deepseek-r1`)
The evaluation uses two datasets:
1. [m-ric/agents_medium_benchmark_2](https://huggingface.co/datasets/m-ric/agents_medium_benchmark_2)
2. [m-ric/smol_agents_benchmark](https://huggingface.co/datasets/m-ric/smol_agents_benchmark)
Both datasets were created by the [smolagents](https://github.com/huggingface/smolagents) team at 🤗 Hugging Face and contain curated tasks from GAIA, GSM8K, SimpleQA, and MATH. We selected these datasets primarily for a quick evaluation of relative performance between models in a `freeact` setup, with the additional benefit of enabling comparisons with smolagents. To ensure fair comparisons with [their published results](https://huggingface.co/blog/smolagents#how-strong-are-open-models-for-agentic-workflows), we used identical evaluation protocols and tools.
[<img src="docs/eval/eval-plot.png" alt="Performance">](docs/eval/eval-plot.png)
When comparing our results with smolagents using Claude 3.5 Sonnet on [m-ric/agents_medium_benchmark_2](https://huggingface.co/datasets/m-ric/agents_medium_benchmark_2) (only dataset with available smolagents [reference data](https://github.com/huggingface/smolagents/blob/c22fedaee17b8b966e86dc53251f210788ae5c19/examples/benchmark.ipynb)), we observed the following outcomes (evaluation conducted on 2025-01-07):
[<img src="docs/eval/eval-plot-comparison.png" alt="Performance comparison" width="60%">](docs/eval/eval-plot-comparison.png)
Interestingly, these results were achieved using zero-shot prompting in `freeact`, while the smolagents implementation utilizes few-shot prompting. You can find all evaluation details [here](evaluation).
Raw data
{
"_id": null,
"home_page": "https://github.com/gradion-ai/freeact",
"name": "freeact",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.14,>=3.11",
"maintainer_email": null,
"keywords": null,
"author": "Martin Krasser",
"author_email": "martin@gradion.ai",
"download_url": "https://files.pythonhosted.org/packages/2d/5b/4f7d4afb7cd44cb76c2e6128faea86486a87d0a3b19ffe8827bd2a23d346/freeact-0.4.0.tar.gz",
"platform": null,
"description": "# freeact\n\n<p align=\"left\">\n <a href=\"https://gradion-ai.github.io/freeact/\"><img alt=\"Website\" src=\"https://img.shields.io/website?url=https%3A%2F%2Fgradion-ai.github.io%2Ffreeact%2F&up_message=online&down_message=offline&label=docs\"></a>\n <a href=\"https://pypi.org/project/freeact/\"><img alt=\"PyPI - Version\" src=\"https://img.shields.io/pypi/v/freeact?color=blue\"></a>\n <a href=\"https://github.com/gradion-ai/freeact/releases\"><img alt=\"GitHub Release\" src=\"https://img.shields.io/github/v/release/gradion-ai/freeact\"></a>\n <a href=\"https://github.com/gradion-ai/freeact/actions\"><img alt=\"GitHub Actions Workflow Status\" src=\"https://img.shields.io/github/actions/workflow/status/gradion-ai/freeact/test.yml\"></a>\n <a href=\"https://github.com/gradion-ai/freeact/blob/main/LICENSE\"><img alt=\"GitHub License\" src=\"https://img.shields.io/github/license/gradion-ai/freeact?color=blueviolet\"></a>\n <a href=\"https://pypi.org/project/freeact/\"><img alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/freeact\"></a>\n</p>\n\nA lightweight library for code-action based agents.\n\n- [Introduction](#introduction)\n- [Key capabilities](#key-capabilities)\n- [Quickstart](#quickstart)\n- [Evaluation](#evaluation)\n- [Supported models](https://gradion-ai.github.io/freeact/models/)\n\n## Introduction\n\n`freeact` is a lightweight agent library that empowers language models to act as autonomous agents through executable **code actions**. By enabling agents to express their actions directly in code rather than through constrained formats like JSON, `freeact` provides a flexible and powerful approach to solving complex, open-ended problems that require dynamic solution paths.\n\nThe library builds upon [recent](https://arxiv.org/abs/2402.01030) [research](https://arxiv.org/abs/2411.01747) demonstrating that code-based actions significantly outperform traditional agent approaches, with studies showing up to 20% higher success rates compared to conventional methods. While existing solutions often restrict agents to predefined tool sets, `freeact` removes these limitations by allowing agents to leverage the full power of the Python ecosystem, dynamically installing and utilizing any required libraries as needed.\n\n## Key capabilities\n\n`freeact` agents can autonomously improve their actions through learning from environmental feedback, execution results, and human guidance. They can store and reuse successful code actions as custom skills in long-term memory. These skills can be composed and interactively refined to build increasingly sophisticated capabilities, enabling efficient scaling to complex tasks.\n\n`freeact` executes all code actions within [`ipybox`](https://gradion-ai.github.io/ipybox/), a secure execution environment built on IPython and Docker that can also be deployed locally. This ensures safe execution of dynamically generated code while maintaining full access to the Python ecosystem. Combined with its lightweight and extensible architecture, `freeact` provides a robust foundation for building adaptable AI agents that can resolve real-world challenges requiring dynamic problem-solving approaches.\n\n## Quickstart\n\nInstall `freeact` using pip:\n\n```bash\npip install freeact\n```\n\nCreate a `.env` file with [Anthropic](https://console.anthropic.com/settings/keys) and [Gemini](https://aistudio.google.com/app/apikey) API keys:\n\n```env title=\".env\"\n# Required for Claude 3.5 Sonnet\nANTHROPIC_API_KEY=...\n\n# Required for generative Google Search via Gemini 2\nGOOGLE_API_KEY=...\n```\n\nLaunch a `freeact` agent with generative Google Search skill using the [CLI](https://gradion-ai.github.io/freeact/cli/):\n\n```bash\npython -m freeact.cli \\\n --model-name=anthropic/claude-3-5-sonnet-20241022 \\\n --ipybox-tag=ghcr.io/gradion-ai/ipybox:basic \\\n --skill-modules=freeact_skills.search.google.stream.api\n```\n\nor an equivalent [quickstart.py](examples/quickstart.py) script:\n\n```python\nimport asyncio\n\nfrom rich.console import Console\n\nfrom freeact import Claude, CodeActAgent, execution_environment\nfrom freeact.cli.utils import stream_conversation\n\n\nasync def main():\n async with execution_environment(\n ipybox_tag=\"ghcr.io/gradion-ai/ipybox:basic\",\n ) as env:\n skill_sources = await env.executor.get_module_sources(\n module_names=[\"freeact_skills.search.google.stream.api\"],\n )\n\n model = Claude(model_name=\"anthropic/claude-3-5-sonnet-20241022\")\n agent = CodeActAgent(model=model, executor=env.executor)\n await stream_conversation(agent, console=Console(), skill_sources=skill_sources)\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\nOnce launched, you can start interacting with the agent:\n\nhttps://github.com/user-attachments/assets/83cec179-54dc-456c-b647-ea98ec99600b\n\n## Evaluation\n\nWe [evaluated](evaluation) `freeact` with the following models:\n\n- Claude 3.5 Sonnet (`claude-3-5-sonnet-20241022`)\n- Claude 3.5 Haiku (`claude-3-5-haiku-20241022`)\n- Gemini 2.0 Flash (`gemini-2.0-flash-exp`)\n- Qwen 2.5 Coder 32B Instruct (`qwen2p5-coder-32b-instruct`)\n- DeepSeek V3 (`deepseek-v3`)\n- DeepSeek R1 (`deepseek-r1`)\n\nThe evaluation uses two datasets:\n\n1. [m-ric/agents_medium_benchmark_2](https://huggingface.co/datasets/m-ric/agents_medium_benchmark_2)\n2. [m-ric/smol_agents_benchmark](https://huggingface.co/datasets/m-ric/smol_agents_benchmark)\n\nBoth datasets were created by the [smolagents](https://github.com/huggingface/smolagents) team at \ud83e\udd17 Hugging Face and contain curated tasks from GAIA, GSM8K, SimpleQA, and MATH. We selected these datasets primarily for a quick evaluation of relative performance between models in a `freeact` setup, with the additional benefit of enabling comparisons with smolagents. To ensure fair comparisons with [their published results](https://huggingface.co/blog/smolagents#how-strong-are-open-models-for-agentic-workflows), we used identical evaluation protocols and tools.\n\n[<img src=\"docs/eval/eval-plot.png\" alt=\"Performance\">](docs/eval/eval-plot.png)\n\nWhen comparing our results with smolagents using Claude 3.5 Sonnet on [m-ric/agents_medium_benchmark_2](https://huggingface.co/datasets/m-ric/agents_medium_benchmark_2) (only dataset with available smolagents [reference data](https://github.com/huggingface/smolagents/blob/c22fedaee17b8b966e86dc53251f210788ae5c19/examples/benchmark.ipynb)), we observed the following outcomes (evaluation conducted on 2025-01-07):\n\n[<img src=\"docs/eval/eval-plot-comparison.png\" alt=\"Performance comparison\" width=\"60%\">](docs/eval/eval-plot-comparison.png)\n\nInterestingly, these results were achieved using zero-shot prompting in `freeact`, while the smolagents implementation utilizes few-shot prompting. You can find all evaluation details [here](evaluation).\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A lightweight library for code-action based agents",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/gradion-ai/freeact"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "48b7c8faefef2d260a152fd3f80444551d980832b6373935730bbce5305b1284",
"md5": "b983f228ca4c293df231773331f21592",
"sha256": "a8dfd59d8771952bccabe1e0b082d37949226eaf9621d10838f03aa3c6c5f304"
},
"downloads": -1,
"filename": "freeact-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b983f228ca4c293df231773331f21592",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.14,>=3.11",
"size": 41347,
"upload_time": "2025-02-20T11:13:57",
"upload_time_iso_8601": "2025-02-20T11:13:57.675669Z",
"url": "https://files.pythonhosted.org/packages/48/b7/c8faefef2d260a152fd3f80444551d980832b6373935730bbce5305b1284/freeact-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2d5b4f7d4afb7cd44cb76c2e6128faea86486a87d0a3b19ffe8827bd2a23d346",
"md5": "379c8933c11c56cf22aa9b9fbe9fd180",
"sha256": "13470e0db84a35761facad1c126934ec60251f6170b9ff0323932c6cf3adaca2"
},
"downloads": -1,
"filename": "freeact-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "379c8933c11c56cf22aa9b9fbe9fd180",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.14,>=3.11",
"size": 32568,
"upload_time": "2025-02-20T11:13:59",
"upload_time_iso_8601": "2025-02-20T11:13:59.099918Z",
"url": "https://files.pythonhosted.org/packages/2d/5b/4f7d4afb7cd44cb76c2e6128faea86486a87d0a3b19ffe8827bd2a23d346/freeact-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-20 11:13:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gradion-ai",
"github_project": "freeact",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "freeact"
}