Skip to content

Commit 96e2aa4

Browse files
authored
Merge pull request #76 from MLAI-AUS-Inc/medhack-frontiers-skill
improving image attachments
2 parents a610f6d + 041d90b commit 96e2aa4

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

roo-standalone/roo/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ async def handle_mention(
102102
return {
103103
"message": result.message,
104104
"skill_used": skill.name,
105-
"data": result.data
105+
"data": result.data,
106+
"blocks": result.blocks,
106107
}
107108
else:
108109
print("💬 No skill matched, generating general response")

roo-standalone/roo/main.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,15 @@ async def _handle_mention(event: dict):
267267
)
268268

269269
if result.get("message"):
270-
post_message(
271-
channel=channel_id,
272-
text=result["message"],
273-
thread_ts=thread_ts
274-
)
275-
270+
post_kwargs = {
271+
"channel": channel_id,
272+
"text": result["message"],
273+
"thread_ts": thread_ts,
274+
}
275+
if result.get("blocks"):
276+
post_kwargs["blocks"] = result["blocks"]
277+
post_message(**post_kwargs)
278+
276279
print(f"✅ Mention handled successfully (skill: {result.get('skill_used')})")
277280

278281
except Exception as e:
@@ -311,12 +314,15 @@ async def _resume_intent(user_id: str, intent: dict):
311314
)
312315

313316
if result.get("message"):
314-
post_message(
315-
channel=channel_id,
316-
text=result["message"],
317-
thread_ts=thread_ts
318-
)
319-
317+
post_kwargs = {
318+
"channel": channel_id,
319+
"text": result["message"],
320+
"thread_ts": thread_ts,
321+
}
322+
if result.get("blocks"):
323+
post_kwargs["blocks"] = result["blocks"]
324+
post_message(**post_kwargs)
325+
320326
except Exception as e:
321327
print(f"❌ Error resuming intent: {e}")
322328
if intent.get("channel"):

roo-standalone/roo/skills/executor.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SkillResult:
2525
message: str
2626
data: Optional[Any] = None
2727
error: Optional[str] = None
28+
blocks: Optional[list] = None
2829

2930

3031
class SkillExecutor:
@@ -85,10 +86,17 @@ async def execute(
8586
# Generic LLM-based execution
8687
result = await self._execute_with_llm(skill, text, params, user_id, thread_history)
8788

89+
# Skill handlers can return a dict with "message" + "blocks" for rich responses
90+
blocks = None
91+
if isinstance(result, dict) and "message" in result:
92+
blocks = result.get("blocks")
93+
result = result["message"]
94+
8895
return SkillResult(
8996
success=True,
9097
message=result,
91-
data=params
98+
data=params,
99+
blocks=blocks
92100
)
93101

94102
except Exception as e:
@@ -341,7 +349,10 @@ async def _execute_medhack(
341349
"Do NOT reveal the correct diagnosis or hint at it."
342350
)
343351
guess_warning = f"\n\n_You have *{remaining}* guess{'es' if remaining != 1 else ''} remaining._"
344-
return llm_response + guess_warning
352+
return self._medhack_game_response(
353+
llm_response + guess_warning,
354+
current_case.get("image_url", "")
355+
)
345356

346357
# --- Game interaction (not a guess) ---
347358
if is_game_q and current_case:
@@ -368,7 +379,8 @@ async def _execute_medhack(
368379
)
369380

370381
case_data = client.get_case_for_llm(today)
371-
return await self._medhack_llm_response(skill, text, case_data, thread_history)
382+
llm_response = await self._medhack_llm_response(skill, text, case_data, thread_history)
383+
return self._medhack_game_response(llm_response, current_case.get("image_url", ""))
372384

373385
if is_game_q and not current_case:
374386
return (
@@ -387,7 +399,8 @@ async def _execute_medhack(
387399
"so you can no longer interact with it. Come back tomorrow for a new one!"
388400
)
389401
case_data = client.get_case_for_llm(today)
390-
return await self._medhack_llm_response(skill, text, case_data, thread_history)
402+
llm_response = await self._medhack_llm_response(skill, text, case_data, thread_history)
403+
return self._medhack_game_response(llm_response, current_case.get("image_url", ""))
391404

392405
# --- Event info mode ---
393406
if is_event_q or (not is_game_q):
@@ -420,6 +433,25 @@ async def _execute_medhack(
420433

421434
return await self._execute_with_llm(skill, text, params, user_id, thread_history)
422435

436+
def _medhack_game_response(self, text: str, image_url: str = "") -> dict | str:
437+
"""Wrap a game response with image blocks when the case has an image_url."""
438+
if image_url:
439+
return {
440+
"message": text,
441+
"blocks": [
442+
{
443+
"type": "image",
444+
"image_url": image_url,
445+
"alt_text": "Patient case image",
446+
},
447+
{
448+
"type": "section",
449+
"text": {"type": "mrkdwn", "text": text},
450+
},
451+
],
452+
}
453+
return text
454+
423455
async def _medhack_llm_response(
424456
self,
425457
skill: Skill,

0 commit comments

Comments
 (0)