Skip to content
Merged
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
9 changes: 9 additions & 0 deletions src/fast_agent/core/fastagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,15 @@ def _apply_instruction_context(
if request_params is not None:
request_params.systemPrompt = resolved

# TODO -- find a cleaner way of doing this
# Keep any attached LLM in sync so the provider sees the resolved prompt
llm = getattr(agent, "_llm", None)
if llm is not None:
if getattr(llm, "default_request_params", None) is not None:
llm.default_request_params.systemPrompt = resolved
if hasattr(llm, "instruction"):
llm.instruction = resolved

def _apply_skills_to_agent_configs(self, default_skills: list[SkillManifest]) -> None:
self._default_skill_manifests = list(default_skills)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/instruction_templates/FOO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This text came from FOO.md and should replace the placeholder.
7 changes: 7 additions & 0 deletions tests/integration/instruction_templates/fastagent.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default_model: passthrough

logger:
level: "error"
progress_display: false
show_chat: false
show_tools: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

import pytest


@pytest.mark.integration
@pytest.mark.asyncio
async def test_file_silent_reaches_llm_request_params(fast_agent):
"""Ensure {{file_silent:...}} is resolved before the LLM sees the system prompt."""
fast = fast_agent
file_text = Path("FOO.md").read_text(encoding="utf-8").strip()

@fast.agent(
name="file_template_agent",
instruction="System prompt start. {{file_silent:FOO.md}}",
model="passthrough",
)
async def agent_function():
async with fast.run() as agent_app:
agent = agent_app.file_template_agent

# Agent-facing instruction should have the file contents applied
assert "{{file_silent:FOO.md}}" not in agent.instruction
assert file_text in agent.instruction

# The LLM request params (what the provider sees) should also be resolved
request_params = agent.llm.get_request_params()
assert request_params.systemPrompt is not None
assert "{{file_silent:FOO.md}}" not in request_params.systemPrompt
assert file_text in request_params.systemPrompt

# Default params should stay in sync for future calls
assert file_text in agent.llm.default_request_params.systemPrompt

response = await agent.send("ping")
assert "ping" in response

await agent_function()
Loading