Creating your first agent
Install Dependencies
Section titled “Install Dependencies”any-agent uses the python asyncio module to support async functionality. When running in Jupyter notebooks, this means we need to enable the use of nested event loops. We’ll install any-agent and enable this below using nest_asyncio.
%pip install 'any-agent' --quiet%pip install ddgs --quiet
import warnings
import nest_asyncio
# Suppress technical warnings to reduce noise for the userwarnings.filterwarnings("ignore", category=DeprecationWarning)warnings.filterwarnings("ignore", category=RuntimeWarning)
nest_asyncio.apply()Configure the Agent
Section titled “Configure the Agent”Pick an LLM
Section titled “Pick an LLM”For this tutorial, we’ll use Mistral’s mistral-small-latest (fast and affordable). You could also use:
gpt-4o-miniclaude-3-5-sonnet-latest- Any other model supported by any-agent
Pick Tools
Section titled “Pick Tools”We’ll use search_web(DuckDuckGo), which provides Duck Duck Go search for free with no API key required.
import osfrom getpass import getpass
if "MISTRAL_API_KEY" not in os.environ: os.environ["MISTRAL_API_KEY"] = getpass("Enter your Mistral API Key: ")from any_agent import AgentConfig, AnyAgentfrom any_agent.tools import search_web
# We use the 'mistral-small-latest' model we promised in the textagent = AnyAgent.create( "tinyagent", AgentConfig(model_id="mistral:mistral-small-latest", tools=[search_web]),)Run the Agent
Section titled “Run the Agent”Now we’ve configured our agent, so it’s time to run it! Let’s give it a simple task: find 5 trending new TV shows that were released recently.
agent_trace = agent.run( "What are 5 tv shows that are trending in 2025? Check a few sites, and provide the name of the show, the exact release date, the genre, and a brief description of the show.")View the results
Section titled “View the results”The agent.run method returns an AgentTrace object, which has a few convenient attributes for displaying some interesting information about the run.
print(agent_trace.final_output) # Final answerprint(f"Duration: {agent_trace.duration.total_seconds():.2f} seconds")print(f"Usage: {agent_trace.tokens.total_tokens:,}")print(f"Cost (USD): {agent_trace.cost.total_cost:.6f}")