From 85a3596b169000a5093b6fd894f407b664819544 Mon Sep 17 00:00:00 2001 From: Paul Walko Date: Fri, 26 Dec 2025 19:42:40 +0100 Subject: [PATCH] optional sources --- discord/src/agent_client.py | 10 ++++++++-- discord/src/main.py | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/discord/src/agent_client.py b/discord/src/agent_client.py index 943528f..bd2e526 100644 --- a/discord/src/agent_client.py +++ b/discord/src/agent_client.py @@ -41,20 +41,26 @@ class AgentClient: logger.warning(f"Agent health check failed: {e}") return False - async def query(self, message: str) -> str: + async def query(self, message: str, sources_only: bool | None = None) -> str: """ Send a query to the agent and return the response. The agent uses AG-UI protocol with SSE streaming. We collect the full response for Discord (which doesn't support streaming). + + Args: + message: The query to send + sources_only: Override the default sources_only setting """ if not self._client: raise RuntimeError("Agent client not initialized") + use_sources_only = sources_only if sources_only is not None else self.sources_only + headers = { "Content-Type": "application/json", "x-user-roles": json.dumps(self.default_roles), - "x-sources-only": "true" if self.sources_only else "false", + "x-sources-only": "true" if use_sources_only else "false", } # AG-UI protocol request format (RunAgentInput) diff --git a/discord/src/main.py b/discord/src/main.py index b97f4f8..f4a1e2e 100644 --- a/discord/src/main.py +++ b/discord/src/main.py @@ -58,11 +58,17 @@ class CavepediaBot(discord.Client): """Called when the bot is starting up.""" await self.agent_client.start() - # Register the cavesearch command - @self.tree.command(name="cavesearch", description="Search the caving knowledge base") + # Register the cavesearch command (sources only) + @self.tree.command(name="cavesearch", description="Search the caving knowledge base (sources only)") @app_commands.describe(query="Your question about caving") async def cavesearch(interaction: discord.Interaction, query: str): - await self.handle_search(interaction, query) + await self.handle_search(interaction, query, sources_only=True) + + # Register the cavechat command (full response) + @self.tree.command(name="cavechat", description="Ask the caving AI assistant") + @app_commands.describe(query="Your question about caving") + async def cavechat(interaction: discord.Interaction, query: str): + await self.handle_search(interaction, query, sources_only=False) # Sync commands to specific guilds for instant availability for guild_id in [1137321345718439959, 1454125232439955471]: @@ -91,8 +97,8 @@ class CavepediaBot(discord.Client): else: logger.warning("Agent server health check failed") - async def handle_search(self, interaction: discord.Interaction, query: str): - """Handle the /cavesearch command.""" + async def handle_search(self, interaction: discord.Interaction, query: str, sources_only: bool): + """Handle the /cavesearch and /cavechat commands.""" # Check if channel is allowed if interaction.channel_id not in self.config.allowed_channels: await interaction.response.send_message( @@ -115,7 +121,7 @@ class CavepediaBot(discord.Client): f"Processing query from {interaction.user} in #{interaction.channel}: {query[:100]}..." ) - response = await self.agent_client.query(query) + response = await self.agent_client.query(query, sources_only=sources_only) # Discord has a 2000 character limit if len(response) > 2000: