Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/features/FIDES_IMPLEMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

**FIDES** is a comprehensive deterministic prompt injection defense system for the agent framework. The implementation provides label-based security mechanisms to defend against prompt injection attacks by tracking integrity and confidentiality of content throughout agent execution.

FIDES enforces tool-result, hidden-variable, caller-replayed, and history-provider flows. Other `ContextProvider`
implementations remain trusted plugins; provider-injected messages require an explicit provider/application trust
boundary until a first-class provider-message labeling contract is defined.

**🚀 Key Features:**
- **Context Provider Pattern** - `SecureAgentConfig` extends `ContextProvider`, injecting tools, instructions, and middleware automatically
- **Automatic Variable Hiding** - UNTRUSTED content is automatically hidden without requiring manual intervention
Expand Down Expand Up @@ -363,4 +367,8 @@ cd python/packages/core && ../../.venv/bin/pytest tests/test_security.py -v
- **Full traceability**: Message-level label tracking
- **Complete auditability**: All security events logged

The system ensures that untrusted content never directly reaches the LLM context and that all tool calls are policy-checked based on the cumulative security state before execution.
The system hides FIDES-labeled untrusted tool output from the LLM context and policy-checks tool calls against the
cumulative security state before execution. Newly supplied assistant/tool messages are conservatively labeled even
when state was restored. History-provider messages reconstruct missing state, while restored state remains
authoritative for unstamped stored history; trusted non-history context providers remain responsible for the data they
inject.
176 changes: 148 additions & 28 deletions python/packages/core/agent_framework/_agents.py

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions python/packages/core/agent_framework/_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,15 @@ def create_next_handler(index: int) -> Callable[[], Awaitable[None]]:
if index >= len(self._middleware):

async def final_wrapper() -> None:
from ._tools import (
_SECURITY_ARGUMENT_MATERIALIZATION_CONTEXT, # pyright: ignore[reportPrivateUsage]
)

security_materialization = _SECURITY_ARGUMENT_MATERIALIZATION_CONTEXT.get()
if security_materialization is not None:
active_context, materialize = security_materialization
if context is active_context:
materialize(context)
context.result = final_handler(context)
if inspect.isawaitable(context.result):
context.result = await context.result
Expand Down
247 changes: 240 additions & 7 deletions python/packages/core/agent_framework/_sessions.py

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions python/packages/core/agent_framework/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def _has_authoritative_approval_session(invocation_session: AgentSession | None)
_SECURITY_ARGUMENTS_SNAPSHOT_CONTEXT_KEY: Final[str] = "_security_function_arguments"
_PREPARED_ARGUMENTS_CONTEXT_KEY: Final[str] = "_prepared_function_arguments"
_AUTO_ARGUMENT_PREPARATION_CONTEXT_KEY: Final[str] = "_auto_prepare_function_arguments"
_SECURITY_ARGUMENT_MATERIALIZATION_CONTEXT: Final[contextvars.ContextVar[tuple[Any, Callable[[Any], None]] | None]] = (
contextvars.ContextVar("_security_argument_materialization_context", default=None)
)
_FUNCTION_INVOCATION_LIMIT_FALLBACK_TEXT: Final[str] = (
"Function invocation limit reached before a final answer could be produced."
)
Expand Down Expand Up @@ -1138,6 +1141,15 @@ async def invoke(
from ._types import Content
from .observability import OBSERVABILITY_SETTINGS

security_materialization = _SECURITY_ARGUMENT_MATERIALIZATION_CONTEXT.get()
if security_materialization is not None:
active_context, materialize = security_materialization
if active_context.function is self and (context is None or context is active_context):
active_context.metadata[_AUTO_ARGUMENT_PREPARATION_CONTEXT_KEY] = True
materialize(active_context)
arguments = active_context.arguments
context = active_context

configured_parser = self.result_parser
skip_parsing = skip_parsing or configured_parser is SKIP_PARSING

Expand Down
Loading
Loading