make the system promet configurable

This commit is contained in:
thierryverse 2025-12-19 19:11:44 +02:00 committed by CREDO23
parent 3208f9bd7b
commit 61fc31ef02

View file

@ -851,16 +851,38 @@ def create_search_knowledge_base_tool(
# ============================================================================= # =============================================================================
def build_surfsense_system_prompt(today: datetime | None = None) -> str: def build_surfsense_system_prompt(
today: datetime | None = None,
user_instructions: str | None = None,
) -> str:
"""
Build the SurfSense system prompt with optional user instructions.
Args:
today: Optional datetime for today's date (defaults to current UTC date)
user_instructions: Optional user instructions to inject into the system prompt
Returns:
Complete system prompt string
"""
resolved_today = (today or datetime.now(UTC)).astimezone(UTC).date().isoformat() resolved_today = (today or datetime.now(UTC)).astimezone(UTC).date().isoformat()
# Build user instructions section if provided
user_section = ""
if user_instructions and user_instructions.strip():
user_section = f"""
<user_instructions>
{user_instructions.strip()}
</user_instructions>
"""
return f""" return f"""
<system_instruction> <system_instruction>
You are SurfSense, a reasoning and acting AI agent designed to answer user questions using the user's personal knowledge base. You are SurfSense, a reasoning and acting AI agent designed to answer user questions using the user's personal knowledge base.
Today's date (UTC): {resolved_today} Today's date (UTC): {resolved_today}
</system_instruction> </system_instruction>{user_section}
<tools> <tools>
You have access to the following tools: You have access to the following tools:
- search_knowledge_base: Search the user's personal knowledge base for relevant information. - search_knowledge_base: Search the user's personal knowledge base for relevant information.
@ -897,6 +919,7 @@ def create_surfsense_deep_agent(
search_space_id: int, search_space_id: int,
db_session: AsyncSession, db_session: AsyncSession,
connector_service: ConnectorService, connector_service: ConnectorService,
user_instructions: str | None = None,
): ):
""" """
Create a SurfSense deep agent with knowledge base search capability. Create a SurfSense deep agent with knowledge base search capability.
@ -906,7 +929,8 @@ def create_surfsense_deep_agent(
search_space_id: The user's search space ID search_space_id: The user's search space ID
db_session: Database session db_session: Database session
connector_service: Initialized connector service connector_service: Initialized connector service
connectors_to_search: List of connector types to search (default: common connectors) user_instructions: Optional user instructions to inject into the system prompt.
These will be added to the system prompt to customize agent behavior.
Returns: Returns:
CompiledStateGraph: The configured deep agent CompiledStateGraph: The configured deep agent
@ -918,11 +942,13 @@ def create_surfsense_deep_agent(
connector_service=connector_service, connector_service=connector_service,
) )
# Create the deep agent # Create the deep agent with user-configurable system prompt
agent = create_deep_agent( agent = create_deep_agent(
model=llm, model=llm,
tools=[search_tool], tools=[search_tool],
system_prompt=build_surfsense_system_prompt(), system_prompt=build_surfsense_system_prompt(
user_instructions=user_instructions
),
context_schema=SurfSenseContextSchema, context_schema=SurfSenseContextSchema,
) )
@ -942,7 +968,7 @@ async def run_test():
# Create ChatLiteLLM from global config # Create ChatLiteLLM from global config
# Use global LLM config by id (negative ids are reserved for global configs) # Use global LLM config by id (negative ids are reserved for global configs)
llm_config = load_llm_config_from_yaml(llm_config_id=-2) llm_config = load_llm_config_from_yaml(llm_config_id=-5)
if not llm_config: if not llm_config:
raise ValueError("Failed to load LLM config from YAML") raise ValueError("Failed to load LLM config from YAML")
llm = create_chat_litellm_from_config(llm_config) llm = create_chat_litellm_from_config(llm_config)
@ -961,6 +987,7 @@ async def run_test():
search_space_id=search_space_id, search_space_id=search_space_id,
db_session=session, db_session=session,
connector_service=connector_service, connector_service=connector_service,
user_instructions="Always fininsh the response with CREDOOOOOOOOOO23",
) )
print("\nAgent created successfully!") print("\nAgent created successfully!")
@ -972,7 +999,7 @@ async def run_test():
print("=" * 60) print("=" * 60)
initial_state = { initial_state = {
"messages": [HumanMessage(content=("What are my notes from last 3 days?"))], "messages": [HumanMessage(content=("Can you tell me about my documents?"))],
"search_space_id": search_space_id, "search_space_id": search_space_id,
} }