Skip to content

Commit a4663be

Browse files
authored
Enhance response model to include excerpts and improve citation descr… (microsoft#589)
…iptions; update team instructions to emphasize providing illustrative excerpts.
1 parent 956214b commit a4663be

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

assistants/project-assistant/assistant/respond.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,20 @@ class CoordinatorMessageList(BaseModel):
460460
class Output(BaseModel):
461461
"""
462462
Attributes:
463-
response: The response from the assistant.
464-
citations: A list of citations for the response provided from the assistant.
463+
citations: A list of citations from which the response is generated. There should always be at least one citation, but it can be empty if the assistant has no relevant information to cite.
464+
excerpt: A verbatim excerpt from one of the cited works that illustrates why this response was given. It should have enough context to get a good idea of what's in that part of the cited work. If there is no relevant excerpt, this will be None.
465465
next_step_suggestion: Suggest more areas to explore using content from the assistant whiteboard to ensure your conversation covers all of the relevant information.
466466
"""
467467

468+
citations: list[str] = Field(
469+
description="A list of citations from which the response is generated. There should always be at least one citation, but it can be empty if the assistant has no relevant information to cite.",
470+
)
471+
excerpt: str | None = Field(
472+
description="A verbatim excerpt from one of the cited works that illustrates why this response was given. It should have enough context to get a good idea of what's in that part of the cited work. If there is no relevant excerpt, this will be None.",
473+
)
468474
response: str = Field(
469475
description="The response from the assistant.",
470476
)
471-
citations: list[str] = Field(
472-
description="A list of citations for the response provided from the assistant.",
473-
)
474477
next_step_suggestion: str = Field(
475478
description="Suggest more areas to explore using content from the assistant whiteboard to ensure your conversation covers all of the relevant information. For example: 'Would you like to explore ... next?'.",
476479
)
@@ -501,21 +504,21 @@ class Output(BaseModel):
501504

502505
# Add the token usage message to the footer items
503506
if completion_response:
504-
reponse_tokens = completion_response.usage.completion_tokens if completion_response.usage else 0
507+
response_tokens = completion_response.usage.completion_tokens if completion_response.usage else 0
505508
request_tokens = token_budget.used
506509
footer_items.append(
507510
get_token_usage_message(
508511
max_tokens=config.request_config.max_tokens,
509-
total_tokens=request_tokens + reponse_tokens,
512+
total_tokens=request_tokens + response_tokens,
510513
request_tokens=request_tokens,
511-
completion_tokens=reponse_tokens,
514+
completion_tokens=response_tokens,
512515
)
513516
)
514517

515518
await context.update_conversation(
516519
metadata={
517520
"token_counts": {
518-
"total": request_tokens + reponse_tokens,
521+
"total": request_tokens + response_tokens,
519522
"max": config.request_config.max_tokens,
520523
}
521524
}
@@ -557,22 +560,31 @@ class Output(BaseModel):
557560
return
558561

559562
# Prepare response and citations.
563+
response_parts: list[str] = []
560564
try:
561565
output_model = Output.model_validate_json(content)
562-
citations = ", ".join(output_model.citations) if output_model.citations else "None"
563-
if role == ConversationRole.COORDINATOR:
564-
output = output_model.response
565-
else:
566-
output = f"{output_model.response}\n\n{output_model.next_step_suggestion}\n\nCitations: _{citations}_"
566+
if output_model.response:
567+
response_parts.append(output_model.response)
568+
569+
if role == ConversationRole.TEAM and output_model.excerpt:
570+
output_model.excerpt = output_model.excerpt.strip().strip('"')
571+
response_parts.append(f'> _"{output_model.excerpt}"_ (excerpt)')
572+
573+
if role == ConversationRole.TEAM and output_model.next_step_suggestion:
574+
response_parts.append(output_model.next_step_suggestion)
575+
576+
if role == ConversationRole.TEAM and output_model.citations:
577+
citations = ", ".join(output_model.citations)
578+
response_parts.append(f"Sources: _{citations}_")
567579

568580
except Exception as e:
569581
logger.exception(f"exception occurred parsing json response: {e}")
570582
metadata["debug"]["error"] = str(e)
571-
output = content
583+
response_parts.append(content)
572584

573585
await context.send_messages(
574586
NewConversationMessage(
575-
content=output,
587+
content="\n\n".join(response_parts),
576588
message_type=MessageType.chat,
577589
metadata=metadata,
578590
)

assistants/project-assistant/assistant/text_includes/knowledge_transfer_team_instructions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Use a helpful, informative tone focused on knowledge sharing and exploration. Ke
1212

1313
## Help the user explore the shared knowledge
1414

15+
- If at all possible, you MUST provide specific illustrative excerpts of the content you used to create your answer.
1516
- With each response, suggest more areas to explore using content from the assistant whiteboard to ensure your conversation covers all of the relevant information.
1617
- For example, if the user has already talked about 3 of five items from the whiteboard, your suggestion in `next_step_suggestion` might be "Would you like to explore [area 4] now?"
1718
- Do NOT suggest exploring areas that are not in the shared knowledge.

0 commit comments

Comments
 (0)