Skip to content

Conversation

pokey
Copy link
Contributor

@pokey pokey commented Oct 17, 2025

This matches pretty_print() from Python, except it just returns the string. You can do console.log(message.prettyPrint()) to get python's pretty_print behaviour

This matches the corresponding implementation in Python. You can now do `console.log(message.prettyPrint())`
@changeset-bot
Copy link

changeset-bot bot commented Oct 17, 2025

🦋 Changeset detected

Latest commit: 5688d88

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@langchain/core Patch
@langchain/standard-tests Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pokey pokey changed the title feat(core): Add prettyPrint method to BaseMessage feat(core): Add BaseMessage.prettyPrint() Oct 17, 2025
};
}

protected override _prettyPrintDetails(): string[] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This duplication with _prettyPrintDetails above is awkward. Seems to be due to the inheritance / interface hierarchy of AIMessageChunk. @hntrl any thoughts on this one? I could obv factor into a function but was hoping to understand the situation a bit better before blindly doing that

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it is a little awkward, and I don't love the repeated code, but I think its fine to have two overrides (this is precedent with some other things in message inheritance as I understand it).

Could hoist this logic and have the methods call it directly (if that's not what you're talking about already)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh where were you thinking we'd hoist it to?

@pokey pokey changed the title feat(core): Add BaseMessage.prettyPrint() feat(core): Add BaseMessage.toFormattedString() Oct 21, 2025
Comment on lines 128 to 134
protected override _toFormattedStringDetails(): string[] {
const lines: string[] = [];
if (this.name) {
lines.push(`Name: ${this.name}`);
}
return lines;
}
Copy link
Member

Choose a reason for hiding this comment

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

later enhancement: tool call id, status, args, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You get those from the original ai message so if you're printing messages in a loop that would end up being a bit redundant. But agreed useful when printing on its own

Also fwiw I believe this is matching what Python pretty print does

@@ -0,0 +1,5 @@
---
"@langchain/core": patch
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think according to semver this would be minor, because it is adding something to public api? Admittedly it is a small thing we're adding; not sure how strictly we're adhering to semver

Copy link
Member

Choose a reason for hiding this comment

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

think you're the first of us to ask that Q post v1! Will confer and let you know

@hntrl
Copy link
Member

hntrl commented Oct 21, 2025

@pokey hope you don't mind, I took some liberties with the implementation to resolve CI issues. When I mentioned hoisting the pretty print function, this is what I had in mind (and maybe lets us introduce other message toString formats later down the line? don't know what that looks like but hey)

@hntrl hntrl merged commit 619ae64 into langchain-ai:main Oct 22, 2025
37 checks passed
lnhsingh added a commit to langchain-ai/docs that referenced this pull request Oct 22, 2025
Just translates the Python version of the supervisor tutorial to js. 

- Depends on langchain-ai/langchainjs#9228
- See also langchain-ai/langchainjs#9235

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Lauren Hirata Singh <[email protected]>
mdrxy pushed a commit to anjaliratnam-msft/docs that referenced this pull request Oct 22, 2025
Just translates the Python version of the supervisor tutorial to js. 

- Depends on langchain-ai/langchainjs#9228
- See also langchain-ai/langchainjs#9235

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Lauren Hirata Singh <[email protected]>
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.

2 participants