The most basic Fast Agent application creates an agent with an instruction and runs it interactively:
examples/setup/agent.py
import asynciofrom fast_agent import FastAgent# Create the applicationfast = FastAgent("fast-agent example")default_instruction = """You are a helpful AI Agent.{{serverInstructions}}{{agentSkills}}{{file_silent:AGENTS.md}}{{env}}The current date is {{currentDate}}."""# Define the agent@fast.agent(instruction=default_instruction)async def main(): # use the --model command line switch or agent arguments to change model async with fast.run() as agent: await agent.interactive()if __name__ == "__main__": asyncio.run(main())
The {{serverInstructions}} template variable automatically includes documentation for any MCP servers connected to your agent.
Create agents with custom Python functions as tools:
examples/tool-use-agent/agent.py
import asynciofrom fast_agent import FastAgentfrom fast_agent.agents.agent_types import AgentConfigfrom fast_agent.agents.tool_agent import ToolAgentfrom fast_agent.context import Contextdef get_video_call_transcript(video_id: str) -> str: return "Assistant: Hi, how can I assist you today?\n\nCustomer: Hi, I wanted to ask you about last invoice I received..."class CustomToolAgent(ToolAgent): def __init__( self, config: AgentConfig, context: Context | None = None, ): tools = [get_video_call_transcript] super().__init__(config, tools, context)fast = FastAgent("Example Tool Use Application")@fast.custom(CustomToolAgent)async def main() -> None: async with fast.run() as agent: await agent.default.generate( "What is the topic of the video call no.1234?", )if __name__ == "__main__": asyncio.run(main())
import asynciofrom fast_agent import FastAgentfast = FastAgent("Data Analysis (Roots)")@fast.agent( name="data_analysis", instruction="""You have access to a Python 3.12 interpreter and you can use this to analyse and process data. Common analysis packages such as Pandas, Seaborn and Matplotlib are already installed. You can add further packages if needed.Data files are accessible from the /mnt/data/ directory (this is the current working directory).Visualisations should be saved as .png files in the current working directory.{{serverInstructions}}""", servers=["interpreter"],)async def main() -> None: async with fast.run() as agent: await agent.interactive() await agent.data_analysis( "There is a csv file in the current directory. " "Analyse the file, produce a detailed description of the data, and any patterns it contains.", ) await agent.data_analysis( "Consider the data, and how to usefully group it for presentation to a Human. Find insights, using the Python Interpreter as needed.\n" "Use MatPlotLib to produce insightful visualisations. Save them as '.png' files in the current directory. Be sure to run the code and save the files.\n" "Produce a summary with major insights to the data", ) await agent()if __name__ == "__main__": asyncio.run(main())