Skip to main content

Base kernel for pydantic-ai kernels

Project description

Pydantic AI Base Kernel

This is wrapper around pydantic-ai agent, that allows to requests it through jupyter kernel.

It is meant to be subclassed to create new kernel-based agent, for adding tools or any special application.

Getting started

Within a python venv,

pip install pydantic-ai-kernel

Any jupyter frontend should be able to dialog with this kernel, for example :

CLI : Install jupyter-console (pip install jupyter-console); and run jupyter console --kernel pydantic_ai

Notebook (you might need to restart the IDE) : select 'pydantic_ai' on top right of the notebook

Silik Signal Messaging : Access the kernel through Signal Message Application, see here

Configuration file

By default, kernel starts by looking for a configuration file here :

~/.jupyter/jupyter_pydantic_ai_kernel_config.yaml

But you can also run the kernel as is; and specify the path to a config file by executing the following message in a cell :

/load_config <path_to_kernel_config_file>

This allows to have different instances of the same kernel, each with its own system prompt and / or inference provider.

Description of the configuration file

The configuration standard is a little bit cumbersome but is made to match the description of agents in pydantic-ai. We describe hereafter this standard.

An Pydantic AI agent is made of :

  • a model

  • information about the agent : tools, system prompt, agent name

The model itself, is composed of several parts :

Here is an example for a local ollama instance :

agent_name: pydantic_ai
system_prompt: You are a specialist in cooking, and you are always ready to help people creating new cooking recipees.
model:
  model_name: qwen3:1.7b
  model_type: openai
  model_provider:
    name: ollama
    params:
      base_url: http://localhost:11434/v1

If you just need to use an external open-ai provider, put :

model:
  model_name: openai:gpt-4o

and specify API key in environment variable.

Scheme can be found here.

Creating your own agents

In order to create custom agents, you just need to create a new kernel, and subclass PydanticAIBaseKernel from this library. See an example here : [https://github.com/mariusgarenaux/rudi-kernel]

You can then create tools, or any mechanism you want. We provide here juste the communication protocol between agent and user, through well known and proven jupyter kernels.

The default configuration file for any subclass of PydanticAIBaseKernel will be fetched from : ~/.jupyter/jupyter_<kernel_name>_config.yaml; and must follows the same scheme as the one of pydantic_ai_kernel. But it can also be specify by sending a message to the kernel : /load_config <path_to_config_file>

Developer - Debug

If you want to see the logs of the kernel; export the environment variable PYDANTIC_AI_KERNEL_LOG to 'True'. You also need to create a dir to save logs at ~/.pydantic_ai_kernel_logs. For subclasses, logger can be accessed with self.logger (e.g. self.logger.debug('hey')).

Dealing with multi-agents

Multi-agents means here several agents that have access to the same context. To do so, you can for example use silik-kernel; an other kernel that allows several kernels to be started and managed through a single one.

You can also start several kernels independantly, and deal with them as you would with several classic jupyter kernels.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_ai_kernel-1.2.8.tar.gz (14.8 kB view details)

Uploaded Source

File details

Details for the file pydantic_ai_kernel-1.2.8.tar.gz.

File metadata

  • Download URL: pydantic_ai_kernel-1.2.8.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pydantic_ai_kernel-1.2.8.tar.gz
Algorithm Hash digest
SHA256 e66ddae5377a8162c9a80b9e90f78c1dbfb12f1e7e9bcb34bf340a6ae74ac40d
MD5 9cb61140b5037d05152723c1168bbc6d
BLAKE2b-256 a28c807afc51fab4a555f7ac2e9cc5d2559c627636aa7a91448094330141eb2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page