Agent¶
The Agent facade is the primary entry point for interacting with Cognitia.
Agent¶
Agent ¶
High-level facade for interacting with the AI agent.
Supports: - query(prompt) โ Result (one-shot) - stream(prompt) โ AsyncIterator[StreamEvent] (streaming) - conversation() โ Conversation (multi-turn)
runtime_factory property ¶
Application-facing runtime factory seam.
runtime_capabilities property ¶
Capability descriptor for the selected runtime for app-level introspection.
query async ¶
One-shot request -> Result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The user prompt (appended as the final user message). | required |
messages | list[Message] | None | Optional conversation history to prepend before the current prompt. Each message is a | None |
query_structured async ¶
One-shot request returning a validated Pydantic model.
Creates a temporary AgentConfig with output_type set, runs query(), and returns the validated structured_output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The user prompt. | required |
output_type | type[T] | A Pydantic BaseModel subclass. The LLM response is parsed and validated against this type. Retry on validation error. | required |
max_retries | int | None | Override max_model_retries for structured output validation. Default: uses the runtime's default (2). | None |
Returns:
| Type | Description |
|---|---|
T | A validated instance of |
Raises:
| Type | Description |
|---|---|
StructuredOutputError | If all retries are exhausted and validation still fails. |
AgentConfig¶
AgentConfig dataclass ¶
Immutable configuration for the Agent facade.
The only required parameter is system_prompt. All others have sensible defaults.
resolved_model property ¶
Deprecated compatibility wrapper for model alias resolution.
Result¶
Result dataclass ¶
Immutable result of a query/stream request.
ok=True if error is None (request succeeded).
StructuredOutputError¶
StructuredOutputError ¶
Bases: Exception
Raised when structured output validation fails after all retries.
Attributes:
| Name | Type | Description |
|---|---|---|
raw_text | The raw LLM response text that failed validation. | |
output_type_name | Name of the expected Pydantic model type. |