Skip to content

Conversation

pokey
Copy link
Contributor

@pokey pokey commented Oct 17, 2025

Just translates the Python version of the supervisor tutorial to js.

@github-actions github-actions bot added langchain For docs changes to LangChain oss labels Oct 17, 2025
@pokey pokey force-pushed the pokey/translate-supervisor-tutorial-to-js branch from 71bf3e4 to 8ba0e0c Compare October 20, 2025 11:39
@pokey pokey force-pushed the pokey/translate-supervisor-tutorial-to-js branch from 8ba0e0c to 14c9da7 Compare October 20, 2025 11:48

**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
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 don't think we have a Python example so I've made this callout js-only for now

@pokey pokey marked this pull request as ready for review October 20, 2025 12:57
@Copilot Copilot AI review requested due to automatic review settings October 20, 2025 12:57
Copy link
Contributor

@Copilot Copilot AI left a 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 <[email protected]>
@Copilot Copilot AI review requested due to automatic review settings October 20, 2025 18:01
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines 405 to 411
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());
}
}
}
Copy link
Member

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 🫠

Copy link
Contributor Author

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


const resume: Record<string, any> = {};
for (const interrupt of interrupts) {
if (interrupt.id === "2b56f299be313ad8bc689eff02973f16") {
Copy link
Member

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?

Copy link
Contributor Author

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

Comment on lines 1401 to 1404
// Customize context received by sub-agent
// Access full thread messages from the config
const currentMessages =
config?.configurable?.pregel_scratchpad?.currentTaskInput?.messages || [];
Copy link
Member

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):

Suggested change
// 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

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 made this fix, but it from what I can tell, InternalAgentState is not actually exported from langchain? Did we want to export that?

@Copilot Copilot AI review requested due to automatic review settings October 21, 2025 10:15
@pokey pokey force-pushed the pokey/translate-supervisor-tutorial-to-js branch from ee29781 to da61d20 Compare October 21, 2025 10:15
Copy link
Contributor

@Copilot Copilot AI left a 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";
Copy link

Copilot AI Oct 21, 2025

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'.

Suggested change
import { tool } from "langchain";
import { tool } from "@langchain/core/tools";

Copilot uses AI. Check for mistakes.


:::js
```typescript
import { createAgent } from "langchain";
Copy link

Copilot AI Oct 21, 2025

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.

Suggested change
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";
Copy link

Copilot AI Oct 21, 2025

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.

Suggested change
import { tool, createAgent } from "langchain";
import { tool } from "@langchain/core/tools";
import { createAgent } from "@langchain/core/agents";

Copilot uses AI. Check for mistakes.

Comment on lines +1124 to +1125
import { createAgent, humanInTheLoopMiddleware } from "langchain"; // [!code highlight]
import { MemorySaver } from "@langchain/langgraph"; // [!code highlight]
Copy link

Copilot AI Oct 21, 2025

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.

Suggested change
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(""),
Copy link

Copilot AI Oct 21, 2025

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([]),
Copy link

Copilot AI Oct 21, 2025

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().

Suggested change
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";
Copy link

Copilot AI Oct 21, 2025

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.

@pokey
Copy link
Contributor Author

pokey commented Oct 21, 2025

Ok I addressed your comments and left responses to a couple

@Copilot Copilot AI review requested due to automatic review settings October 22, 2025 12:57
Copy link
Contributor

@Copilot Copilot AI left a 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.

@lnhsingh lnhsingh merged commit 3e74969 into langchain-ai:main Oct 22, 2025
4 checks passed
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

langchain For docs changes to LangChain oss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants