Learning skills by example
A freeact
agent can also learn skills from code examples in documentation or other sources instead of skill modules directly. These sources are usually retrieved by the agent itself using spezialized skills, like a Firecrawl MCP server as in the following example, but can also be provided by a user or an application directly in context. In the following example, Python code is scraped from the API documentation of Readwise Reader and used generate a code action for downloading documents from the user's Reader account.
import asyncio
import os
from rich.console import Console
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={"READWISE_API_KEY": os.environ["READWISE_API_KEY"]},
) as env:
async with env.code_provider() as provider:
await provider.register_mcp_servers(
{
"firecrawl": {
"command": "npx",
"args": ["-y", "firecrawl-mcp"],
"env": {"FIRECRAWL_API_KEY": os.getenv("FIRECRAWL_API_KEY")},
}
}
)
skill_sources = await provider.get_sources(mcp_tool_names={"firecrawl": ["firecrawl_scrape"]})
async with env.code_executor() as executor:
model = LiteCodeActModel(
model_name="gpt-4.1",
skill_sources=skill_sources,
api_key=os.getenv("OPENAI_API_KEY"),
)
agent = CodeActAgent(model=model, executor=executor)
await stream_conversation(agent, console=Console())
if __name__ == "__main__":
asyncio.run(main())