Skip to main content

adapters.jupyter_ai_adapter

Jupyter AI agent adapter.

Wraps a Jupyter AI agent to implement the BaseAgent interface, enabling use with protocol adapters.

JupyterAIAdapter Objects

class JupyterAIAdapter(BaseAgent)

Adapter for Jupyter AI agents.

Wraps a Jupyter AI agent to provide a consistent interface for protocol adapters.

Example:

from jupyter_ai import ChatHandler

Create Jupyter AI handler

jupyter_handler = ChatHandler(...)

agent = JupyterAIAgent( handler=jupyter_handler, name="jupyter_ai_agent", description="A Jupyter AI assistant", )

response = await agent.run("Hello!", context)

__init__

def __init__(handler: Any,
name: str = "jupyter_ai_agent",
description: str = "A Jupyter AI powered agent",
version: str = "1.0.0")

Initialize the Jupyter AI agent adapter.

Arguments:

  • handler - The Jupyter AI chat handler instance.
  • name - Agent name.
  • description - Agent description.
  • version - Agent version.

name

@property
def name() -> str

Get the agent name.

description

@property
def description() -> str

Get the agent description.

version

@property
def version() -> str

Get the agent version.

tools

@property
def tools() -> list[ToolDefinition]

Get available tools.

get_tools

def get_tools() -> list[ToolDefinition]

Get the list of tools available to this agent.

Returns:

List of tool definitions.

initialize

async def initialize() -> None

Initialize the agent.

run

async def run(prompt: str, context: AgentContext) -> AgentResponse

Run the agent with a prompt.

Arguments:

  • prompt - User prompt.
  • context - Execution context.

Returns:

Agent response.

stream

async def stream(prompt: str,
context: AgentContext) -> AsyncIterator[StreamEvent]

Stream agent responses.

Arguments:

  • prompt - User prompt.
  • context - Execution context.

Yields:

Stream events.

cancel

async def cancel() -> None

Cancel the current execution.

cleanup

async def cleanup() -> None

Clean up resources.