638e3f3e1e
Check Cross-Plugin Imports / check (push) Has been cancelled
- F-PERM: app/ai/agent_permissions.py (230 lines) — AgentPermissionContext, resolve_agent_permissions(), filter_visible_agents(), check_agent_execute_permission(), optimistic locking - F-APPR: app/core/approval.py (160 lines) + app/routes/approvals.py (305 lines) + migration 0123 — ApprovalRequest model, CRUD API, approve/reject/expire - F-AIUSE: app/ai/ai_use_case.py (156 lines) — AIUseCaseMetadata Pydantic model, validate_ai_use_case() - F-TRANS: app/ai/transparency.py (60 lines) — mark_as_ai_generated(), is_ai_participant() - F-DATA-POL: app/ai/data_policy.py (210 lines) — enforce_data_policy() with SENSITIVE_FIELDS + provider compliance - F-OVERSIGHT: app/ai/oversight.py (108 lines) — DecisionRecord, create_decision_record() - F-DRY: agent_loop.py updated with dry_run parameter - F-AUDIT: agent_loop.py updated with audit log for tool calls - agent_routes.py: AI use case metadata endpoints added - main.py: approval routes registered - All Python compile checks pass
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
"""AI transparency helpers.
|
|
|
|
Provides utilities to mark content as AI-generated and to detect whether a
|
|
communication participant is an AI agent. This is the transparency layer
|
|
required by the AI governance framework: any content produced by an AI agent
|
|
must be identifiable as such.
|
|
|
|
Used by:
|
|
- ``app/plugins/builtins/kommunikation`` — marking AI agent messages
|
|
- ``app/ai/agent_loop.py`` — tagging final outputs as AI-generated
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
from typing import Any
|
|
|
|
# Participant types that represent an AI agent (not a human user).
|
|
AI_PARTICIPANT_TYPES = ("agent", "ai", "system_ai")
|
|
|
|
|
|
def mark_as_ai_generated(content: str, metadata: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
"""Add AI transparency metadata to content.
|
|
|
|
Args:
|
|
content: The AI-generated content.
|
|
metadata: Optional dict with ``model`` and ``provider`` keys plus any
|
|
additional context to record.
|
|
|
|
Returns:
|
|
A dict with the original content plus an ``ai_generated`` flag and an
|
|
``ai_metadata`` block containing model, provider, timestamp, and any
|
|
extra metadata passed in.
|
|
"""
|
|
metadata = metadata or {}
|
|
return {
|
|
"content": content,
|
|
"ai_generated": True,
|
|
"ai_metadata": {
|
|
"model": metadata.get("model", "unknown"),
|
|
"provider": metadata.get("provider", "unknown"),
|
|
"timestamp": datetime.now(UTC).isoformat(),
|
|
**metadata,
|
|
},
|
|
}
|
|
|
|
|
|
def is_ai_participant(participant_id: str, participant_type: str) -> bool:
|
|
"""Check if a participant is an AI agent.
|
|
|
|
Args:
|
|
participant_id: The participant's ID (unused for the check, kept for
|
|
API symmetry and future heuristics).
|
|
participant_type: The participant type string (e.g. ``user``,
|
|
``agent``, ``ai``, ``system_ai``).
|
|
|
|
Returns:
|
|
``True`` if the participant type is an AI agent type.
|
|
"""
|
|
return participant_type in AI_PARTICIPANT_TYPES
|