Skip to content
Draft
56 changes: 55 additions & 1 deletion docs/devel_doc/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -16281,6 +16281,29 @@
"title": "OkpConfiguration",
"description": "OKP (Offline Knowledge Portal) provider configuration.\n\nControls provider-specific behaviour for the OKP vector store.\nOnly relevant when ``\"okp\"`` is listed in ``rag.retrieval.inline.sources``\nor ``rag.retrieval.tool.sources``."
},
"OkpProductFilter": {
"properties": {
"product": {
"type": "string",
"title": "Product"
},
"versions": {
"items": {
"type": "string"
},
"type": "array",
"title": "Versions",
"default": []
}
},
"additionalProperties": false,
"type": "object",
"required": [
"product"
],
"title": "OkpProductFilter",
"description": "One product restriction for the OKP MCP ``search`` tool.\n\nThe server matches ``product`` exactly and OR-combines ``versions``.\nAn empty ``versions`` tuple matches that product at any version.\nSeveral filters on one source are OR-combined.\n\nAttributes:\n product: Product slug, for example ``openshift_container_platform``.\n versions: Versions to include, for example ``(\"4.19\", \"4.20\")``."
},
"OpenAIInferenceProviderConfig": {
"properties": {
"api_key": {
Expand Down Expand Up @@ -19008,6 +19031,37 @@
}
}
]
},
"okp_products": {
"anyOf": [
{
"items": {
"$ref": "#/components/schemas/OkpProductFilter"
},
"type": "array"
},
{
"type": "null"
}
],
"title": "Okp Products",
"description": "Optional list of product restrictions for the OKP knowledge source. Each entry names one product. Versions are OR-combined, and an empty versions list matches every version of that product. Several entries are OR-combined. When omitted, OKP is not restricted by product.",
"examples": [
[
{
"product": "openshift_container_platform",
"versions": [
"4.19",
"4.20"
]
}
],
[
{
"product": "rhel"
}
]
]
}
},
"additionalProperties": false,
Expand All @@ -19016,7 +19070,7 @@
"query"
],
"title": "QueryRequest",
"description": "Model representing a request for the LLM (Language Model).\n\nAttributes:\n query: The query string.\n conversation_id: The optional conversation ID (UUID).\n provider: The optional provider.\n model: The optional model.\n system_prompt: The optional system prompt.\n attachments: The optional attachments.\n no_tools: Whether to bypass all tools and MCP servers (default: False).\n generate_topic_summary: Whether to generate topic summary for new conversations.\n media_type: The optional media type for response format (application/json or text/plain).\n vector_store_ids: The optional list of specific vector store IDs to query for RAG.\n shield_ids: The optional list of configured shield names to apply.\n solr: Optional Solr inline RAG options (mode, filters) or legacy filter-only dict.",
"description": "Model representing a request for the LLM (Language Model).\n\nAttributes:\n query: The query string.\n conversation_id: The optional conversation ID (UUID).\n provider: The optional provider.\n model: The optional model.\n system_prompt: The optional system prompt.\n attachments: The optional attachments.\n no_tools: Whether to bypass all tools and MCP servers (default: False).\n generate_topic_summary: Whether to generate topic summary for new conversations.\n media_type: The optional media type for response format (application/json or text/plain).\n vector_store_ids: The optional list of specific vector store IDs to query for RAG.\n shield_ids: The optional list of configured shield names to apply.\n solr: Optional Solr inline RAG options (mode, filters) or legacy filter-only dict.\n okp_products: The optional list of product restrictions for the OKP knowledge source.",
"examples": [
{
"attachments": [
Expand Down
24 changes: 18 additions & 6 deletions src/agent/capabilities/knowledge/factory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""Factory for building knowledge capabilities from knowledge source settings."""

from dataclasses import replace
from typing import Optional

from sentence_transformers import CrossEncoder

from agent.types.settings import KnowledgeSourceSettings
from agent.types.settings.knowledge import KnowledgeSettings, OKPKnowledgeSourceSettings
from configuration import configuration
from knowledge.capability import Knowledge
from knowledge.registry import KnowledgeSourceRegistry
from knowledge.sources.base import KnowledgeSource
from knowledge.sources.okp import OkpKnowledgeSource
from log import get_logger
from providers.inference.errors import (
ModelNotAvailableError,
Expand All @@ -25,7 +28,7 @@ class KnowledgeFactory: # pylint: disable=too-few-public-methods

@staticmethod
def build_capabilities(
settings: list[KnowledgeSourceSettings],
settings: KnowledgeSettings,
) -> Optional[Knowledge]:
"""Build a knowledge capability from knowledge source settings.

Expand All @@ -35,8 +38,8 @@ def build_capabilities(
configuration. Each source's score weight is applied after merged
matches are ranked. When inline reranking is enabled, the
cross-encoder is loaded from the inference provider registry and
attached to the capability. OKP search mode and the chunk filter are
fixed on the registered OKP source.
attached to the capability. OKP product filters from the request are
applied on a copy of the registered OKP source.

Parameters:
settings: Per-request knowledge source selection.
Expand All @@ -48,12 +51,12 @@ def build_capabilities(
cannot be resolved.

"""
if sources := _get_enabled_sources(settings):
if sources := _get_enabled_sources(settings.sources):
return Knowledge(
sources=sources,
reranker=_get_reranker(),
auto_max_matches=configuration.rag.retrieval.inline.max_chunks,
tool_max_matches=configuration.rag.retrieval.tool.max_chunks,
tool_max_matches=settings.tool_max_matches or configuration.rag.retrieval.tool.max_chunks,
)
return None

Expand All @@ -68,7 +71,8 @@ def _get_enabled_sources(

Returns:
Registered sources whose settings are enabled. Disabled settings and
unknown ids are skipped. Unknown ids are logged.
unknown ids are skipped. Unknown ids are logged. An OKP source with
request product filters is a copy of the registered source.

"""
registry = KnowledgeSourceRegistry()
Expand All @@ -83,6 +87,14 @@ def _get_enabled_sources(
setting.id,
)
continue
if isinstance(setting, OKPKnowledgeSourceSettings) and setting.products:
if isinstance(source, OkpKnowledgeSource):
source = replace(source, products=tuple(setting.products))
else:
logger.warning(
"Knowledge source '%s' is not an OKP source; ignoring product filters",
setting.id,
)
sources.append(source)
return sources

Expand Down
23 changes: 21 additions & 2 deletions src/agent/capabilities/step_persistence/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@

from pydantic_ai_harness.step_persistence import StepPersistence

from agent.types.settings import StepPersistenceSettings
from conversations.agent_history import AgentHistoryService


class StepPersistenceFactory: # pylint: disable=too-few-public-methods
"""Factory for building step persistence capabilities."""

@staticmethod
def build_capability() -> Optional[StepPersistence]:
"""Build a step persistence capability from step persistence settings."""
def build_capability(
settings: StepPersistenceSettings,
) -> Optional[StepPersistence]:
"""Build a step persistence capability from step persistence settings.

Disabled settings produce no capability. Enabled settings return the
capability owned by the agent history service, which is ``None`` when
persistence is configured as a no-op.

Parameters:
settings: Step persistence settings, including whether persistence
is enabled for this agent.

Returns:
The history service capability, or ``None`` when persistence is
disabled or no store is configured.

"""
if not settings.enabled:
return None
return AgentHistoryService().step_persistence
13 changes: 9 additions & 4 deletions src/agent/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ async def create_agent(
*(await MCPFactory.build_capabilities(settings.mcp_servers)),
*ShieldFactory.build_capabilities(settings.shields),
SkillFactory.build_capabilities(settings.skills),
KnowledgeFactory.build_capabilities(settings.knowledge_sources),
KnowledgeFactory.build_capabilities(settings.knowledge),
CompactionFactory.build_capability(settings.compaction),
StepPersistenceFactory.build_capability(),
StepPersistenceFactory.build_capability(settings.step_persistence),
)
capabilities = [
capability for capability in raw_capabilities if capability is not None
]

return Agent(
model=model, instructions=settings.instructions, capabilities=capabilities
model_settings = settings.model_settings.to_model_settings()

return Agent[object, str](
model=model,
model_settings=model_settings,
instructions=settings.instructions,
capabilities=capabilities,
)
6 changes: 5 additions & 1 deletion src/agent/types/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"""Per-request agent settings derived from a query and loaded configuration."""
"""Per-request agent settings derived from API requests."""

from agent.types.settings.agent import AgentSettings
from agent.types.settings.compaction import CompactionSettings
from agent.types.settings.knowledge import KnowledgeSourceSettings
from agent.types.settings.mcp import MCPSettings
from agent.types.settings.model import AgentModelSettings
from agent.types.settings.shield import ShieldSettings
from agent.types.settings.skill import SkillSettings
from agent.types.settings.step_persistence import StepPersistenceSettings

__all__ = [
"AgentModelSettings",
"AgentSettings",
"CompactionSettings",
"KnowledgeSourceSettings",
"MCPSettings",
"ShieldSettings",
"SkillSettings",
"StepPersistenceSettings",
]
23 changes: 17 additions & 6 deletions src/agent/types/settings/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from fastapi import Request

from agent.types.settings.compaction import CompactionSettings
from agent.types.settings.knowledge import KnowledgeSourceSettings
from agent.types.settings.knowledge import KnowledgeSettings
from agent.types.settings.mcp import MCPSettings
from agent.types.settings.model import AgentModelSettings
from agent.types.settings.shield import ShieldSettings
from agent.types.settings.skill import SkillSettings
from agent.types.settings.step_persistence import StepPersistenceSettings
from configuration import configuration
from models.api.requests import QueryRequest
from utils.prompts import get_system_prompt
Expand All @@ -23,13 +25,17 @@ class AgentSettings: # pylint: disable=too-many-instance-attributes

provider: Optional[str] = None
model: Optional[str] = None
model_settings: AgentModelSettings = field(default_factory=AgentModelSettings)
instructions: Optional[str] = None

compaction: CompactionSettings = field(default_factory=CompactionSettings)
step_persistence: StepPersistenceSettings = field(
default_factory=StepPersistenceSettings
)

skills: list[SkillSettings] = field(default_factory=list)
shields: list[ShieldSettings] = field(default_factory=list)
knowledge_sources: list[KnowledgeSourceSettings] = field(default_factory=list)
knowledge: KnowledgeSettings = field(default_factory=KnowledgeSettings)
mcp_servers: list[MCPSettings] = field(default_factory=list)

@classmethod
Expand All @@ -40,10 +46,13 @@ def from_query_request(

Query values select the provider, model, and instructions. Omitted
provider and model fall back to the configured inference defaults.
Shields, knowledge sources, and MCP servers always include every
configured entry. Omitted shield and knowledge-source ids leave them
Model settings stay empty because a query does not set generation or
loop limits. Shields, knowledge sources, and MCP servers always include
every configured entry. Omitted shield and knowledge-source ids leave them
enabled; a provided list disables the rest. ``no_tools`` disables
every MCP server. Skills and compaction come from configuration.
every MCP server. Skills, compaction, and step persistence come from
configuration. The query does not select step persistence, so it stays
enabled and the history service decides whether a store exists.
MCP headers are taken from the HTTP request and the auth token.

Parameters:
Expand All @@ -60,10 +69,12 @@ def from_query_request(
return cls(
provider=provider,
model=model,
model_settings=AgentModelSettings.from_query_request(query_request),
instructions=get_system_prompt(query_request.system_prompt),
compaction=CompactionSettings.from_query_request(query_request),
step_persistence=StepPersistenceSettings.from_query_request(query_request),
skills=SkillSettings.from_query_request(query_request),
shields=ShieldSettings.from_query_request(query_request),
knowledge_sources=KnowledgeSourceSettings.from_query_request(query_request),
knowledge=KnowledgeSettings.from_query_request(query_request),
mcp_servers=MCPSettings.from_query_request(request, query_request, token),
)
Loading
Loading