optional sources
All checks were successful
Build and Push Discord Bot Docker Image / build (push) Successful in 1m0s

This commit is contained in:
2025-12-26 19:42:40 +01:00
parent 805095893c
commit 85a3596b16
2 changed files with 20 additions and 8 deletions

View File

@@ -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)

View File

@@ -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: