Repository navigation
fix: [Agent] When adding conversation logs to the knowledge base, the added structural content is empty. #7738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a review of the changes:
Potential Issues
1.
get("content")may returnNone→TypeErrorinjoinIf any matching message has no
"content"key (or it'sNone),str.joinraisesTypeError: sequence item N: expected str instance, NoneType found.Fix:
2. Accessing
messageswithout guardIf
chat_recordis a model instance from an older DB record lackingmessages, or if it'sNone, this will fail. Consider defensive handling:3. Type inconsistency risk with
problem_textchat_record.question.get("content")— ifquestionisNoneor not a dict,.getfails. Also unclear whether"content"can beNone. You may want a.strip()/ fallback for title integrity.4. Behavior change / backward compatibility
Previously used
chat_record.answer_textandchat_record.problem_text. If those are denormalized fields that some legacy records still rely on (andmessages/questionare nullable), this change could produce emptycontent/titleon older rows. Verify a migration/backfill path exists.5. Multiple TEXT messages concatenated without separator
"".join(...)concatenates raw strings. If messages carry paragraphs or need separators (e.g.,"\n"), you'll merge words. Confirm the intended semantics:Optimization Suggestions
1. Avoid list-then-join; use generator
2. Compute
text_to_chunk(answer_text)onceCurrently called once — good — but consider extracting into a local to avoid accidental duplication in future edits.
3. Batch
get_or_createfor ProblemsIn a loop, each
Problem.objects.get_or_create(...)hits the DB. For large batches, prefetch existing problems first:Then create missing ones in bulk.
4. Consider
bulk_createforParagraphandProblemParagraphMappingInside a
forloop overchat_record_list, all inserts are per-row. For performance at scale, accumulate into lists andbulk_create(..., batch_size=...)outside the loop.5. Consistency of text extraction
Extracting text logic (
join TEXT messages) is now inline. If used elsewhere (e.g., achat_record.answer_textproperty previously), consider centralizing as a helper/property to keep behavior uniform across the codebase.6. Empty-string edge case
If
answer_textis""(no TEXT messages), you'll create aParagraphwith empty content and empty chunks. Decide whether to skip such records:Minor
uuid.uuid7()— ensure Python version supports it (3.14+ oruuid_utils). Not caused by this diff, but worth verifying against your runtime.@@ -393,15 +393,17 @@) suggests added lines; confirm indentation consistency (the snippet looks fine).