¶ciel.runtime — Runtime de agentes y tools
Núcleo del runtime: DTOs de chat (ChatMessage, ChatChoice, ChatRequest,
ChatResponse), contratos de provider/modelo (ChatProvider, ModelProvider),
tool loop y despacho de herramientas (ToolProvider, DefaultToolDispatcher),
resultados de ejecución (ToolLoopResult, AgentRuntimeResult, AgentContext)
y el runtime concreto con trazas (DefaultAgentRuntime, AgentRuntime).
¶ChatMessage.content (multimodal)
ChatMessage.content es str | list[dict[str, Any]]:
str— texto plano (compatibilidad total con versiones previas).list[dict]— partes multimodales (text,image_url,input_audio). Los providers convierten estas partes a su formato nativo automáticamente.
ChatMessage.text() -> str concatena las partes de tipo "text" e ignora
imágenes/audio (ver docs/api-reference/providers.md para los serializers por
proveedor y ejemplos de partes).
¶
ciel.runtime
¶
ContentPart = Dict[str, Any]
module-attribute
¶
AgentContext
dataclass
¶
AgentRuntime
Async runtime contract for tool-loop execution and streaming.
Source code in src/ciel/runtime/__init__.py
¶
AgentRuntimeResult
dataclass
¶
AuditEvent
dataclass
Source code in src/ciel/observability/__init__.py
¶
ChatChoice
dataclass
¶
ChatMessage
dataclass
Source code in src/ciel/runtime/tools.py
¶
text() -> str
Extract plain text from content, tolerant to multimodal parts.
strcontent is returned verbatim.listcontent concatenates thetextof every part whose type is"text"but drops images/audio/video, so consumers (CLI, compression,AgentResponse.text) see only readable text.
Source code in src/ciel/runtime/tools.py
¶
ChatProvider
Bases: ABC
Source code in src/ciel/providers/__init__.py
¶
ChatRequest
dataclass
Source code in src/ciel/runtime/tools.py
¶
ChatResponse
dataclass
¶
CielError
¶
DefaultAgentRuntime
Concrete runtime wiring provider + tool execution with tracing.
Source code in src/ciel/runtime/__init__.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
¶
run_agent_loop(*, request: ChatRequest, tenant_id: Optional[str] = None, toolset: Optional[str] = None, limit: int = 32) -> AgentRuntimeResult
async
Run the agentic tool loop (multi-turn ReAct when tools are present).
The loop issues up to limit model completions. After each completion
that requests tool calls, the requested tools are dispatched and their
results are appended as messages; the model is then called again. The
loop stops when (a) the model returns no tool calls (finish_reason
stop), (b) limit turns are exhausted, or (c) there are no tools
registered in the request.
Backward compatibility: when limit <= 1 or request.tools is
empty, exactly one completion is produced and no tool messages are
appended (the historical single-step behaviour). Every tool result from
every turn is preserved in loop_results so the facade can surface
the full tool_results list.
Source code in src/ciel/runtime/__init__.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
¶
stream_tokens(*, request: ChatRequest, tenant_id: Optional[str] = None, toolset: Optional[str] = None) -> AsyncIterator[str]
async
Stream incremental assistant tokens from the provider.
Calls provider.stream (real SSE streaming) and re-emits the
partial content of each incremental :class:ChatResponse as it
arrives, so callers see the answer grow token by token.
Source code in src/ciel/runtime/__init__.py
¶
DefaultToolDispatcher
Dispatch tool requests to a configured ToolProvider.
Source code in src/ciel/runtime/__init__.py
¶
InMemoryAuditSink
¶
ModelProvider
Model/provider contract for completions (legacy alias).
Source code in src/ciel/runtime/__init__.py
¶
NullAuditSink
¶
ProviderRegistry
Source code in src/ciel/providers/__init__.py
¶
SkillError
¶
SkillLibrary
Writable, in-memory skill store that wraps a :class:SkillRegistry.
The registry remains the source of truth for disk-loaded skills; the
library layer adds creation, registration, update (with version bump) and
removal of skills that live only in memory. Tenant isolation is supported
via the optional tenant_id key on each stored :class:Skill.
Source code in src/ciel/runtime/skills_lib.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
¶
create_from_code(*, name: str, description: str, code: str, category: Optional[str] = None, tenant_id: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None) -> Skill
Compile code (syntax check) and store it as a new skill.
Raises :class:SkillError if the code does not compile. The skill is
NOT executed here — execution belongs to :class:SkillVerifier.
Source code in src/ciel/runtime/skills_lib.py
¶
history(name: str) -> List[Skill]
¶
load_from_disk() -> List[Skill]
Discover skills from the registry roots and index them in-memory.
¶
register(skill: Skill) -> Skill
Register an already-built :class:Skill (e.g. disk-loaded).
Source code in src/ciel/runtime/skills_lib.py
¶
update(*, name: str, description: Optional[str] = None, code: Optional[str] = None, category: Optional[str] = None, bump: str = 'patch') -> Skill
Create a new version of an existing skill, preserving history.
bump is one of major/minor/patch (semantic) and is
recorded in metadata.version. The previous version is preserved in
history(name).
Source code in src/ciel/runtime/skills_lib.py
¶
SkillVerificationError
Bases: SkillError
Raised when a skill fails verification.
¶
SkillVerificationResult
dataclass
Outcome of :meth:SkillVerifier.verify.
Source code in src/ciel/runtime/skills_lib.py
¶
SkillVerifier
Offline verifier: syntax check + executable test cases.
A test case is a dict {"call": {...}, "expect": <value>}. The verifier
executes the skill code in an isolated namespace, looks up a callable named
after the skill (or the first callable defined), invokes it with call
arguments and compares the result to expect.
Source code in src/ciel/runtime/skills_lib.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
¶
StaticToolProvider
Bases: ToolProvider
Source code in src/ciel/runtime/__init__.py
¶
TenantRequired
¶
Tool
dataclass
¶
ToolExecutionContext
Source code in src/ciel/runtime/tools.py
¶
ToolLoopResult
dataclass
Source code in src/ciel/runtime/tools.py
¶
ToolProvider
dataclass
Concrete tool provider used by the runtime's tool dispatcher.
Source code in src/ciel/runtime/__init__.py
¶
ToolRegistry
Source code in src/ciel/runtime/tools.py
¶
ToolResult
dataclass
¶
ToolSpec
dataclass
¶
ToolsetSchema
dataclass
Source code in src/ciel/runtime/tools.py
¶
_extract_tool_calls(response: ChatResponse) -> List[Dict[str, Any]]
Source code in src/ciel/runtime/__init__.py
¶
assert_tenant_event(event: AuditEvent) -> None
¶
propagate(event: AuditEvent, *, tenant_id: Optional[str] = None) -> AuditEvent
Source code in src/ciel/observability/__init__.py
¶
ChatContent = 'str | list[ContentPart]'
module-attribute
¶
ContentPart = Dict[str, Any]
module-attribute
¶
__all__ = ['ToolSpec', 'Tool', 'ToolResult', 'ToolProvider', 'StaticToolProvider', 'DefaultToolDispatcher', 'ToolCallContext', 'ToolsetSchema', 'ToolExecutionContext', 'ToolRegistry', 'TenantAwareToolProvider', 'ChatMessage', 'ChatChoice', 'ChatRequest', 'ChatResponse', 'ModelProvider', 'ToolLoopResult', 'AgentRuntimeResult', 'AgentContext', 'AgentRuntime']
module-attribute
¶
AgentContext
dataclass
¶
AgentRuntime
Async runtime contract for tool-loop execution and streaming.
Source code in src/ciel/runtime/tools.py
¶
AgentRuntimeResult
dataclass
¶
ChatChoice
dataclass
¶
ChatMessage
dataclass
Source code in src/ciel/runtime/tools.py
¶
text() -> str
Extract plain text from content, tolerant to multimodal parts.
strcontent is returned verbatim.listcontent concatenates thetextof every part whose type is"text"but drops images/audio/video, so consumers (CLI, compression,AgentResponse.text) see only readable text.
Source code in src/ciel/runtime/tools.py
¶
ChatRequest
dataclass
Source code in src/ciel/runtime/tools.py
¶
ChatResponse
dataclass
¶
DefaultToolDispatcher
Dispatch tool requests to a configured ToolProvider.
Source code in src/ciel/runtime/tools.py
¶
ModelProvider
Model/provider contract for completions.
Source code in src/ciel/runtime/tools.py
¶
StaticToolProvider
Bases: ToolProvider
Source code in src/ciel/runtime/tools.py
¶
TenantAwareToolProvider
Tenant-aware provider contract.
Source code in src/ciel/runtime/tools.py
¶
Tool
dataclass
¶
ToolCallContext
dataclass
Source code in src/ciel/runtime/tools.py
¶
ToolExecutionContext
Source code in src/ciel/runtime/tools.py
¶
ToolLoopResult
dataclass
Source code in src/ciel/runtime/tools.py
¶
ToolProvider
Contract: discover tools and execute tool calls.
Source code in src/ciel/runtime/tools.py
¶
ToolRegistry
Source code in src/ciel/runtime/tools.py
¶
ToolResult
dataclass
¶
ToolSpec
dataclass
¶
ToolsetSchema
dataclass
Source code in src/ciel/runtime/tools.py
Built-in tools shipped with Ciel.
All tools are defined as ToolSpec + callable and registered into the
builtins toolset by register_builtin_tools. Network/sandbox tools are
safe to import offline; their side effects only happen at execution time and
can be sandboxed via ciel.sandbox.SandboxContext.
¶
BUILTIN_TOOLS: tuple[Tool, ...] = (ECHO_TOOL, DATETIME_TOOL, HTTP_GET_TOOL, FILE_READ_TOOL, SHELL_TOOL)
module-attribute
¶
BUILTIN_TOOLSET = ToolsetSchema(name='builtins', description='Ciel built-in tools (echo, datetime, http_get, file_read, shell).', tools=(tuple((t.spec) for t in BUILTIN_TOOLS)))
module-attribute
¶
DATETIME_TOOL = Tool(spec=(ToolSpec(name='datetime', description='Return current UTC time.', parameters={'format': {'type': 'string'}})), callable_=_datetime)
module-attribute
¶
ECHO_TOOL = Tool(spec=(ToolSpec(name='echo', description='Echo back the provided text.', parameters={'text': {'type': 'string'}})), callable_=_echo)
module-attribute
¶
FILE_READ_TOOL = Tool(spec=(ToolSpec(name='file_read', description='Read a local file (sandboxed).', parameters={'path': {'type': 'string'}})), callable_=_file_read)
module-attribute
¶
HTTP_GET_TOOL = Tool(spec=(ToolSpec(name='http_get', description='GET a URL (requires network).', parameters={'url': {'type': 'string'}, 'timeout': {'type': 'number'}})), callable_=_http_get)
module-attribute
¶
SHELL_TOOL = Tool(spec=(ToolSpec(name='shell', description='Run a shell command (disabled by default policy).', parameters={'command': {'type': 'string'}})), callable_=_shell)
module-attribute
¶
SandboxContext
dataclass
Source code in src/ciel/sandbox/__init__.py
¶
SandboxPolicy
dataclass
¶
Tool
dataclass
¶
ToolResult
dataclass
¶
ToolSpec
dataclass
¶
ToolsetSchema
dataclass
Source code in src/ciel/runtime/tools.py
¶
_datetime(arguments: Dict[str, Any], *, tool_call_id: str = '', tenant_id: Optional[str] = None) -> ToolResult
Source code in src/ciel/runtime/tools_builtins.py
¶
_echo(arguments: Dict[str, Any], *, tool_call_id: str = '', tenant_id: Optional[str] = None) -> ToolResult
¶
_file_read(arguments: Dict[str, Any], *, tool_call_id: str = '', tenant_id: Optional[str] = None) -> ToolResult
Source code in src/ciel/runtime/tools_builtins.py
¶
_http_get(arguments: Dict[str, Any], *, tool_call_id: str = '', tenant_id: Optional[str] = None, client: Optional[httpx.AsyncClient] = None) -> ToolResult
async
Source code in src/ciel/runtime/tools_builtins.py
¶
_shell(arguments: Dict[str, Any], *, tool_call_id: str = '', tenant_id: Optional[str] = None) -> ToolResult
Source code in src/ciel/runtime/tools_builtins.py
¶
register_builtin_tools(registry) -> None
Register all built-in tools into a ToolRegistry instance.
¶
__all__ = ['MemoryStore', 'MemoryEntry', 'init_schema', '_fts5_available']
module-attribute
¶
MemoryEntry
dataclass
¶
MemoryStore
Bases: SqliteStateBackend
Alias retrocompatible a :class:SqliteStateBackend (SQLite en disco).
MemoryStore es SQLite en disco desde F5 — el nombre engaña. Para
F15 se refactorizó para heredar de StateBackend de modo que cualquier
store que hoy recibe un MemoryStore puede recibir también un
PostgresStateBackend compartido sin cambios de API.
Se sigue construyendo con la misma firma: MemoryStore(db_path).
Source code in src/ciel/runtime/memory.py
¶
SqliteStateBackend
Bases: StateBackend
Backend SQLite en disco (default offline). Hereda el esquema de F15-.
Mantiene FTS5 cuando está disponible; si no, search degrada a lista
vacía (comportamiento idéntico al MemoryStore original).
Source code in src/ciel/runtime/state_backend.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
¶
_fts5_available(conn) -> bool
¶
init_schema(conn) -> None
Source code in src/ciel/runtime/state_backend.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |