-
Notifications
You must be signed in to change notification settings - Fork 256
Translate supervisor tutorial to js #981
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
Translate supervisor tutorial to js #981
Conversation
71bf3e4
to
8ba0e0c
Compare
8ba0e0c
to
14c9da7
Compare
|
||
**Important:** Make sure sub-agent prompts emphasize that their final message should contain all relevant information. A common failure mode is sub-agents that perform tool calls but don't include the results in their final response. | ||
|
||
:::js |
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.
I don't think we have a Python example so I've made this callout js-only for now
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.
Pull Request Overview
This PR translates the supervisor agent tutorial from Python to JavaScript, creating language-specific versions of the tutorial content. The PR adds comprehensive JavaScript examples alongside the existing Python content, including tool definitions, agent creation, human-in-the-loop patterns, and advanced customization examples.
Key Changes
- Added JavaScript/TypeScript code examples throughout the tutorial using custom language fences (
:::js
and:::python
) - Updated navigation structure in docs.json to make the supervisor tutorial accessible from both Python and JavaScript sections
- Included JavaScript-specific installation instructions and imports
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
src/oss/langchain/supervisor.mdx | Added comprehensive JavaScript translations of all code examples, including tool definitions, agent creation, streaming patterns, and human-in-the-loop workflows |
src/docs.json | Updated navigation to reference the shared supervisor tutorial from both Python and JavaScript tutorial sections |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
for (const update of Object.values(step)) { | ||
if (update && typeof update === "object" && "messages" in update) { | ||
for (const message of update.messages) { | ||
console.log(message.prettyPrint()); | ||
} | ||
} | ||
} |
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.
this looked odd until I realized that stream steps are just cast as any
types 🫠
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.
yeah this was the cleanest I could come up with, but does actually result in a type error. Should I add an explicit any
cast? Would be good to revisit at some point to see if we can come up with something clean that keeps strong types
src/oss/langchain/supervisor.mdx
Outdated
|
||
const resume: Record<string, any> = {}; | ||
for (const interrupt of interrupts) { | ||
if (interrupt.id === "2b56f299be313ad8bc689eff02973f16") { |
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.
hmm don't think this is desired?
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.
nice catch. I've fixed the ts but left the python
src/oss/langchain/supervisor.mdx
Outdated
// Customize context received by sub-agent | ||
// Access full thread messages from the config | ||
const currentMessages = | ||
config?.configurable?.pregel_scratchpad?.currentTaskInput?.messages || []; |
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.
The preferred way to introspect state (currently):
// Customize context received by sub-agent | |
// Access full thread messages from the config | |
const currentMessages = | |
config?.configurable?.pregel_scratchpad?.currentTaskInput?.messages || []; | |
// Customize context received by sub-agent | |
// Access full thread messages from the config | |
const currentMessages = getCurrentTaskInput<InternalAgentState>(config).messages; |
importing InternalAgentState from langchain and getCurrentTaskInput
from langgraph
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.
I made this fix, but it from what I can tell, InternalAgentState
is not actually exported from langchain
? Did we want to export that?
ee29781
to
da61d20
Compare
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
|
||
:::js | ||
```typescript | ||
import { tool } from "langchain"; |
Copilot
AI
Oct 21, 2025
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.
The import statement references a non-existent module. The tool
function should be imported from '@langchain/core/tools' rather than 'langchain'.
import { tool } from "langchain"; | |
import { tool } from "@langchain/core/tools"; |
Copilot uses AI. Check for mistakes.
|
||
:::js | ||
```typescript | ||
import { createAgent } from "langchain"; |
Copilot
AI
Oct 21, 2025
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.
The import statement references a non-existent module. The createAgent
function should be imported from a specific LangChain package (likely '@langchain/langgraph' or similar) rather than the generic 'langchain' package.
import { createAgent } from "langchain"; | |
import { createAgent } from "@langchain/langgraph"; |
Copilot uses AI. Check for mistakes.
* that are wrapped as tools. | ||
*/ | ||
|
||
import { tool, createAgent } from "langchain"; |
Copilot
AI
Oct 21, 2025
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.
The import statement references a non-existent module. Both tool
and createAgent
should be imported from their correct packages: tool
from '@langchain/core/tools' and createAgent
from the appropriate LangChain package.
import { tool, createAgent } from "langchain"; | |
import { tool } from "@langchain/core/tools"; | |
import { createAgent } from "@langchain/core/agents"; |
Copilot uses AI. Check for mistakes.
import { createAgent, humanInTheLoopMiddleware } from "langchain"; // [!code highlight] | ||
import { MemorySaver } from "@langchain/langgraph"; // [!code highlight] |
Copilot
AI
Oct 21, 2025
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.
The import statement references a non-existent module. These functions should be imported from their specific packages rather than the generic 'langchain' package.
import { createAgent, humanInTheLoopMiddleware } from "langchain"; // [!code highlight] | |
import { MemorySaver } from "@langchain/langgraph"; // [!code highlight] | |
import { createAgent, humanInTheLoopMiddleware, MemorySaver } from "@langchain/langgraph"; // [!code highlight] |
Copilot uses AI. Check for mistakes.
startTime: z.string().describe("ISO format: '2024-01-15T14:00:00'"), | ||
endTime: z.string().describe("ISO format: '2024-01-15T15:00:00'"), | ||
attendees: z.array(z.string()).describe("email addresses"), | ||
location: z.string().optional().default(""), |
Copilot
AI
Oct 21, 2025
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.
Chaining .default()
after .optional()
is incorrect. Either use .optional()
alone (which makes the field optional with undefined as default) or use .default('')
without .optional()
.
Copilot uses AI. Check for mistakes.
to: z.array(z.string()).describe("email addresses"), | ||
subject: z.string(), | ||
body: z.string(), | ||
cc: z.array(z.string()).optional().default([]), |
Copilot
AI
Oct 21, 2025
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.
Chaining .default()
after .optional()
is incorrect. Either use .optional()
alone (which makes the field optional with undefined as default) or use .default([])
without .optional()
.
cc: z.array(z.string()).optional().default([]), | |
cc: z.array(z.string()).default([]), |
Copilot uses AI. Check for mistakes.
|
||
:::js | ||
```typescript | ||
import { getCurrentTaskInput } from "@langchain/langgraph"; |
Copilot
AI
Oct 21, 2025
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.
The function getCurrentTaskInput
does not exist in '@langchain/langgraph'. Verify the correct import path for accessing task input in LangChain.js.
Copilot uses AI. Check for mistakes.
Ok I addressed your comments and left responses to a couple |
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
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 <175728472+Copilot@users.noreply.github.com> Co-authored-by: Lauren Hirata Singh <lauren@langchain.dev>
Just translates the Python version of the supervisor tutorial to js.
BaseMessage.toFormattedString()
langchainjs#9228