Imports and Setup
This cell sets up the environment and imports necessary libraries:- Pathlib, os, json, asyncio, etc. for file and system operations.
- Imports from the
autogen
andmcp
libraries, which are used to create conversational agents and connect to an arXiv-related tool server. nest_asyncio.apply()
ensures that asynchronous code runs properly in Jupyter notebooks.
Define MCP Server Path
Set the path to the MCP server script, which will be used to handle tool execution related to arXiv paper retrieval.Agents
- Define the joker agent, whose role is to make jokes in the style of Shakespeare.
- Use a
pydantic
model to structure the joke and explanation. - Set LLM configuration, including temperature, caching, and model.
- Define a
ContextVariables
object to inject context (like joke constraints) into the agent’s workflow.
Create Toolkit and Run
- Asynchronously create a toolkit from the client session and
registers it to a
mcp_agent
that will search and download arXiv papers. - Set up a handoff: once
mcp_agent
finishes its task, it passes control tojoker
. - Delete the
.cache/
folder to reset the environment. - Initialize a DefaultPattern for how agents interact.
- Start the group chat workflow using
a_initiate_group_chat
.