Skip to content

Add concurrency and fast-stop to generate_answers#291

Merged
bmerkle merged 3 commits into
microsoft:mainfrom
bmerkle:main
Jul 14, 2026
Merged

Add concurrency and fast-stop to generate_answers#291
bmerkle merged 3 commits into
microsoft:mainfrom
bmerkle:main

Conversation

@bmerkle

@bmerkle bmerkle commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Runs generate_answer() over search results concurrently (bounded by AnswerGeneratorSettings.concurrency) and, when fast_stop is enabled, skips results that haven't started once another has already produced a good answer. Mirrors answerGenerator.ts's concurrency/fastStop behavior for the array-of-search-results case.

Runs generate_answer() over search results concurrently (bounded by
AnswerGeneratorSettings.concurrency) and, when fast_stop is enabled,
skips results that haven't started once another has already produced
a good answer. Mirrors answerGenerator.ts's concurrency/fastStop
behavior for the array-of-search-results case.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 12, 2026 22:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configurable concurrency and “fast stop” behavior to generate_answers() so multiple generate_answer() calls can run concurrently (bounded), and optionally stop starting new work once a good answer is found—aligning with the described TypeScript behavior. Tests are added to validate the concurrency cap and fast-stop skipping semantics.

Changes:

  • Introduced AnswerGeneratorSettings and a concurrent implementation path for generate_answers().
  • Implemented _generate_answers_concurrently() using an asyncio.Semaphore plus an asyncio.Event to support fast-stop.
  • Added async tests covering concurrency limiting and fast-stop vs non-fast-stop behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/typeagent/knowpro/answers.py Adds settings + concurrent/fast-stop execution for answer generation.
tests/test_answers.py Adds tests validating concurrency limiting and fast-stop behavior.

Comment thread src/typeagent/knowpro/answers.py Outdated
Comment thread src/typeagent/knowpro/answers.py Outdated

@robgruen robgruen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we address the two copilot comments? I think this is the preferred behavior and if it differs from what's in the TS implementation I'll update that to match.

bmerkle and others added 2 commits July 13, 2026 20:32
Address PR microsoft#291 review feedback: AnswerGeneratorSettings previously
defaulted to concurrency=2/fast_stop=True, silently changing behavior
for existing callers that don't pass settings. Default to concurrency=1,
fast_stop=False (matching the prior sequential, run-everything
behavior), overridable via TYPEAGENT_ANSWER_CONCURRENCY and
TYPEAGENT_ANSWER_FAST_STOP env vars or explicit settings. Also clarify
the generate_answers() return-value comment now that fast_stop can
return fewer answers than search_results.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Drop the bespoke _default_concurrency/_default_fast_stop helpers with
try/except in favor of the plain os.getenv(NAME, default) style already
used elsewhere in the codebase (e.g. outlook_dump.py). Document the new
TYPEAGENT_ANSWER_CONCURRENCY / TYPEAGENT_ANSWER_FAST_STOP vars in
.env-template alongside the other optional settings.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@bmerkle

bmerkle commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@robgruen thanks for your feedback. is fixed now

@bmerkle
bmerkle requested a review from robgruen July 14, 2026 21:03

@robgruen robgruen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for this change/improvement!

@bmerkle
bmerkle merged commit 9b3ae62 into microsoft:main Jul 14, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants