chatomon.connectors.pydantic_ai
¶
Build an atom into a native PydanticAI agent.
Install with pip install 'chatomon[pydantic-ai]'.
Classes:
| Name | Description |
|---|---|
PydanticAIConnector |
Builds an atom into a native |
PydanticAIConnector
¶
PydanticAIConnector(
model: Model | str,
*,
resolve_model: (
Callable[[str], Model | str] | None
) = None,
**agent_kwargs: Any
)
Bases: Connector['Agent[Any, str]']
Builds an atom into a native pydantic_ai.Agent.
chatomon's capability is the outermost layer; your own capabilities run
inside it. Extra keyword arguments go to pydantic_ai.Agent unchanged
(tools, deps_type, model_settings, ...). With output orbitals, use
run() / run_sync(): streaming is refused because PydanticAI streams
text before it can be checked. The reply must come from the model: a run
in which a capability answers in its place or changes its reply fails with
ChatomonConfigError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model | str
|
The nucleus model: a PydanticAI model object or a
|
required |
resolve_model
|
Callable[[str], Model | str] | None
|
Maps the model id of a JudgeOrbital to a PydanticAI model; by default the id is used as a model string. |
None
|
**agent_kwargs
|
Any
|
Passed to |
{}
|
Raises:
| Type | Description |
|---|---|
ChatomonConfigError
|
If |
Examples:
from pydantic_ai.models.test import TestModel
from chatomon import Atom
from chatomon.connectors.pydantic_ai import PydanticAIConnector
atom = Atom(
name="speedypack",
instructions="You are the customer assistant of SpeedyPack.",
connector=PydanticAIConnector(TestModel(custom_output_text="Hi!")),
)
agent = atom.build()
assert agent.run_sync("hello").output == "Hi!"
Methods:
| Name | Description |
|---|---|
build |
Build the native agent with chatomon's capability installed. |
generate_structured |
Make one structured call with a throwaway PydanticAI agent. |
Source code in src/chatomon/connectors/pydantic_ai.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
build
¶
Build the native agent with chatomon's capability installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atom
|
Atom[Agent[Any, str]]
|
The validated atom. |
required |
engine
|
Engine
|
The engine that runs the atom's orbitals. |
required |
Returns:
| Type | Description |
|---|---|
Agent[Any, str]
|
A |
Source code in src/chatomon/connectors/pydantic_ai.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
generate_structured
async
¶
Make one structured call with a throwaway PydanticAI agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model id; passed through |
required |
system
|
str
|
System instructions. |
required |
prompt
|
str
|
User prompt. |
required |
schema
|
type[ModelT]
|
Output type. |
required |
Returns:
| Type | Description |
|---|---|
ModelT
|
The validated output. |
Source code in src/chatomon/connectors/pydantic_ai.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |