Iris: Automatically switch the context of an active conversation - #701
Iris: Automatically switch the context of an active conversation#701Senan04 wants to merge 14 commits into
Iris: Automatically switch the context of an active conversation#701Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a validated ChangesChat context switching
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Student
participant ChatAgent
participant switch_chat_context
participant ChatPipeline
participant ArtemisAPI
Student->>ChatAgent: ask about another exercise or lecture
ChatAgent->>switch_chat_context: request target mode and entity ID
switch_chat_context->>ChatPipeline: record suggested context
ChatPipeline->>ArtemisAPI: send final result with suggested_context
ArtemisAPI-->>Student: process context switch with final answer
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Claudia-Anthropica
left a comment
There was a problem hiding this comment.
@Senan04 The state and status plumbing looks clean, but the lecture-switching path cannot currently discover a target lecture ID or retrieve outside the active lecture. That blocks a core advertised flow; see the inline comment.
bassner
left a comment
There was a problem hiding this comment.
Locally verified end-to-end with Artemis #13292 in isolated OrbStack containers. The switch_chat_context tool validated and emitted the text-exercise target, and Artemis applied and rendered the context switch with the final response.
Claudia-Anthropica
left a comment
There was a problem hiding this comment.
@Senan04 The course-wide lecture lookup and dynamic retargeting fix the functional blocker. The requested A→B regression still needs to exercise retrieval after the switch and verify it queries lecture B; I left the exact assertion in the existing thread.
The A to B test stopped after recording the switch, so the retrieval side of the flow stayed unverified. Drive the real providers and assert the retriever queries the new lecture without the old lecture unit.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@iris/tests/test_switch_chat_context_tool.py`:
- Around line 309-318: Update the serializer used by ChatRunCallback.send_result
to omit fields whose values are None, specifically ensuring suggested_context
does not produce a suggestedContext key when no switch is provided. Change
test_send_result_without_switch_omits_suggested_context to assert that
"suggestedContext" is absent from the payload rather than equal to None.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 81c70041-f995-458c-b5fd-b1b532db20d3
📒 Files selected for processing (8)
iris/src/iris/pipeline/prompts/templates/chat_system_prompt.j2iris/src/iris/tools/__init__.pyiris/src/iris/tools/chat_tool_providers.pyiris/src/iris/tools/lecture_content_retrieval.pyiris/src/iris/tools/lecture_list.pyiris/src/iris/tools/switch_chat_context.pyiris/tests/test_lecture_list_tool.pyiris/tests/test_switch_chat_context_tool.py
🚧 Files skipped from review as they are similar to previous changes (3)
- iris/src/iris/tools/init.py
- iris/src/iris/pipeline/prompts/templates/chat_system_prompt.j2
- iris/src/iris/tools/switch_chat_context.py
Claudia-Anthropica
left a comment
There was a problem hiding this comment.
@Senan04 The requested A-to-B regression now exercises the provided retrieval tool and verifies the new lecture scope, and the implementation looks good. Approving this update.
There was a problem hiding this comment.
One gap: in a course with lectures but no ingested content the lecture path never switches. provide_lecture_list is gated on allow_lecture_tool, so the agent gets no lecture IDs, while the prompt tells it to look one up and never guess. Gating on dto.course.lectures would be enough.
Predixx
left a comment
There was a problem hiding this comment.
Tested locally against Artemis #13292 with a real LLM. Course → exercise, exercise → exercise and back to course all switch correctly, including the marker and the session mode.
|
There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions. |
Claudia-Anthropica
left a comment
There was a problem hiding this comment.
@Senan04 The merge preserves the context-switching and dynamic-retrieval paths, and the Iris test check passes. However, the previously noted [medium] lecture-discovery gap remains: provide_lecture_list is gated by allow_lecture_tool, which is false when a course has lectures but no indexed lecture units, leaving the agent unable to obtain a target lecture ID and perform the advertised switch. Make lecture-list availability depend on state.dto.course.lectures rather than retrieval-index availability, and cover that provider case with a regression test.
|
@Claudia-Anthropica review |
|
@bassner acknowledged, queuing this up for immediate review! |
Claudia-Anthropica
left a comment
There was a problem hiding this comment.
@Senan04 The new commits correctly decouple lecture-list availability from indexed lecture content, and the captured Iris test and lint checks pass. However, the same-run exercise-switch path can still use tools bound to the previous exercise and misattribute its submission data to the target. Please prevent original-context exercise tools from serving data after a switch, as detailed inline.
thynguyentumde
left a comment
There was a problem hiding this comment.
Tested locally along with the Artemis PR. Confirmed Iris can detect and switch context automatically.
Note
This should be tested with PR #13292 on Artemis
Summary
Iris can now switch the context of a running chat on its own. When a student asks about a different exercise or lecture than the currently active context, the agent looks up the target's ID, calls the new
switch_chat_contexttool, and then answers about the new context. The requested target travels to Artemis on the final result status update, which applies the switch together with the answer.This is the Pyris side of the feature. The Artemis counterpart is ls1intum/Artemis#13292 and both PRs have to be deployed together.
Motivation
Students have to change the context of a chat manually through the context selection menu. Whenever they ask about another exercise or lecture without doing so, Iris answers with the wrong context in its prompt and its retrieval tools operate on the previous entity. Letting the agent request the switch removes that manual step.
Changes
switch_chat_contexttool (iris/src/iris/tools/switch_chat_context.py): takes a target mode (PROGRAMMING_EXERCISE_CHAT,TEXT_EXERCISE_CHAT,LECTURE_CHAT,COURSE_CHAT) and an entity id. It validates the target against the execution DTO: unknown modes are rejected, exercise and lecture ids that do not exist in the course are rejected with a message that tells the agent which tool to use for the correct id, exercise types other than programming and text are rejected, and a mixed-up programming/text mode is silently corrected from the exercise type on the DTO. A switch to the course always uses the course id from the DTO, and a switch to the already active context clears the pending switch instead of registering a no-op. The tool changes nothing inside the running pipeline, it only records the target.lecture_listtool (iris/src/iris/tools/lecture_list.py,course_dto.py): lecture content retrieval reports lecture names but never lecture ids, and it only ever sees the active lecture, so it cannot supply the id a lecture switch needs. The new tool returns the id, the name and the lecture unit names of every lecture of the course, which gives the agent a non-guessing path from a lecture the student names to the id the switch takes. It reads the newlecturesfield onCourseDTO, which Artemis fills in the accompanying PR. An Artemis instance that does not send the field yet leaves the list empty: the provider logs a warning so the version skew stays visible, and the tool degrades to an empty list rather than failing. Lecture id validation inswitch_chat_contextis skipped in that case, leaving the check to Artemis.lecture_content_retrieval.py,chat_tool_providers.py): retrieval used to bind its lecture scope when the tool was created, so a switch during a run left it pointed at the old lecture and the agent could not answer about the new one. The tool now resolves the scope at call time through a supplier that reads the pending switch. A retrieval after a switch to another lecture covers that lecture as a whole, without the lecture unit filter of the previous context, and a switch away from a lecture context widens retrieval to the whole course.abstract_agent_pipeline.py,chat_tool_providers.py):AgentPipelineExecutionStatecarries apending_context_switch, reset at the start of every run. The newprovide_switch_chat_contextprovider wires the tool's callback to that field, so the last call wins.suggested_context_dto.py,chat_status_update_dto.py,chat_pipeline.py,status_update.py): the newSuggestedContextDTO(mode plusentityId) is attached to the final result status update and serialized under thesuggestedContextalias that Artemis expects. A run without a switch sendssuggestedContext: null, the same shape the other optional fields of the status DTO use when they are unset.chat_system_prompt.j2): a context switching block states the currently active context and instructs the agent to look up the target id first, call the tool, and then answer in the new context. It names the exercise list tool for exercises and the lecture list tool for lectures, and it states that lecture content retrieval is scoped to the active lecture and does not help in finding another one. Worked examples cover both the exercise case and the lecture case, where the agent calls lecture content retrieval again after the switch to reach the content of the new lecture. The block rules out switching on a passing mention or a comparison, requires a switch back to the course context for general course-level questions, and asks the agent to keep the announcement short because Artemis renders a context switch divider. The block is skipped for the MCQ variant.Tests
tests/test_switch_chat_context_tool.pycovers target validation and correction for exercises, lectures and the course, the no-op switch to the active context, and the wire shape ofsuggestedContextin both directions. The lecture A to B case runs through the real tool providers: it performs the switch and then invokes the lecture retrieval tool the pipeline hands the agent, asserting that the retriever is queried for the new lecture and without the lecture unit of the old one.tests/test_lecture_list_tool.pycovers the lecture list output, including a lecture whose units are all unreleased and a course whose lectures Artemis did not send.Summary by CodeRabbit
New Features
suggestedContextwith mode and entity ID.Improvements
Tests