Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SetConfirmationPolicyRequest,
SetSecurityAnalyzerRequest,
StartConversationRequest,
StartGoalRequest,
Success,
UpdateConversationRequest,
UpdateSecretsRequest,
Expand Down Expand Up @@ -294,6 +295,94 @@ async def run_conversation(
return Success()


@conversation_router.post(
"/{conversation_id}/goal",
responses={
404: {"description": "Item not found"},
409: {"description": "Conversation run or goal loop is already running"},
},
)
async def start_goal_in_conversation(
conversation_id: UUID,
request: StartGoalRequest,
conversation_service: ConversationService = Depends(get_conversation_service),
) -> Success:
"""Start a ``/goal`` loop inside an existing conversation.

The loop appends messages and starts agent runs in the same conversation
history and event stream as the main chat. It does not create a separate
conversation for the goal or fork the existing one.
"""
event_service = await conversation_service.get_event_service(conversation_id)
if event_service is None:
raise HTTPException(status.HTTP_404_NOT_FOUND)

try:
await event_service.start_goal_loop(
request.objective, max_iterations=request.max_iterations
)
except ValueError as e:
message = str(e)
if message in ("conversation_already_running", "goal_already_running"):
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Conversation run or goal loop already running.",
)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message)

return Success()


@conversation_router.post(
"/{conversation_id}/goal/stop",
responses={404: {"description": "Item not found"}},
)
async def stop_goal_in_conversation(
conversation_id: UUID,
conversation_service: ConversationService = Depends(get_conversation_service),
) -> Success:
"""Stop the active ``/goal`` loop inside this conversation.

This cancels only the background goal loop, not the conversation itself, and
records an ``interrupted`` goal status so ``/goal/resume`` can continue it.
"""
event_service = await conversation_service.get_event_service(conversation_id)
if event_service is None:
raise HTTPException(status.HTTP_404_NOT_FOUND)
await event_service.stop_goal_loop()
return Success()


@conversation_router.post(
"/{conversation_id}/goal/resume",
responses={
404: {"description": "Item not found"},
409: {"description": "Conversation run or goal loop is already running"},
},
)
async def resume_goal_in_conversation(
conversation_id: UUID,
conversation_service: ConversationService = Depends(get_conversation_service),
) -> Success:
"""Resume the last interrupted ``/goal`` loop inside this conversation."""
event_service = await conversation_service.get_event_service(conversation_id)
if event_service is None:
raise HTTPException(status.HTTP_404_NOT_FOUND)

try:
await event_service.resume_goal_loop()
except ValueError as e:
message = str(e)
if message in ("conversation_already_running", "goal_already_running"):
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Conversation run or goal loop already running.",
)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message)

return Success()


@conversation_router.post(
"/{conversation_id}/secrets", responses={404: {"description": "Item not found"}}
)
Expand Down
Loading
Loading