This commit is contained in:
Tat Dat Duong
2025-05-13 12:14:59 -07:00
parent 4ee8a9e5d8
commit 2eeb1a9ea9
9 changed files with 22 additions and 28 deletions
+1
View File
@@ -0,0 +1 @@
{}
-2
View File
@@ -4,8 +4,6 @@
"private": true,
"type": "module",
"scripts": {
"dev": "tsx scripts/dev.ts",
"dev:hitl": "tsx scripts/dev-hitl.ts",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"format": "prettier --write .",
"agent": "langgraphjs dev",
View File
+4 -5
View File
@@ -7,9 +7,9 @@
* @module email_assistant
*
* @structure
* ┌─────────────────────────────────────────────────────────────────────────┐
* ┌─────────────────────────────────────────────────────────────────────────
* │ Email Assistant │
* ├─────────────────────────────────────────────────────────────────────────┤
* ├─────────────────────────────────────────────────────────────────────────
* │ COMPONENTS │
* │ - LLM : GPT-4 model for decision making │
* │ - Tools : Collection of tools for agent actions │
@@ -32,7 +32,7 @@
* │ - llmCallNode() : Generates responses using LLM │
* │ - triageRouterNode() : Classifies incoming emails │
* │ - shouldContinue() : Routes graph based on agent output │
* └─────────────────────────────────────────────────────────────────────────┘
* └─────────────────────────────────────────────────────────────────────────
*/
// LangChain imports for chat models
@@ -48,7 +48,7 @@ import { ToolNode } from "@langchain/langgraph/prebuilt";
import "@langchain/langgraph/zod";
// LOCAL IMPORTS
import { getTools, getToolsByName } from "./tools/base.js";
import { getTools } from "./tools/base.js";
import {
triageSystemPrompt,
triageUserPrompt,
@@ -63,7 +63,6 @@ import { BaseEmailAgentState, BaseEmailAgentStateType } from "./schemas.js";
import { parseEmail, formatEmailMarkdown } from "./utils.js";
import { AIMessage, BaseMessage, HumanMessage } from "@langchain/core/messages";
import { z } from "zod";
const hasToolCalls = (
message: BaseMessage,
+6 -6
View File
@@ -7,12 +7,12 @@
* @module email_assistant_hitl
*
* @structure
* ┌─────────────────────────────────────────────────────────────────────────┐
* ┌─────────────────────────────────────────────────────────────────────────
* │ HITL Email Assistant │
* ├─────────────────────────────────────────────────────────────────────────┤
* ├─────────────────────────────────────────────────────────────────────────
* │ COMPONENTS │
* │ - LLM : GPT-4 model for decision making │
* │
* │ - Tools : Collection of tools for agent actions │
* │ │
* │ GRAPH NODES │
* │ - triage_router : Classifies emails (ignore/respond/notify) │
@@ -34,7 +34,7 @@
* │ - triageRouterNode() : Classifies incoming emails │
* │ - triageInterruptHandlerNode(): Processes notifications with human input │
* │ - shouldContinue() : Routes graph based on agent output │
* └─────────────────────────────────────────────────────────────────────────┘
* └─────────────────────────────────────────────────────────────────────────
*/
// LangChain imports for chat models
@@ -96,8 +96,8 @@ const hasToolCalls = (
*/
export const initializeHitlEmailAssistant = async () => {
// Get tools
const tools = await getTools();
const toolsByName = await getToolsByName();
const tools = getTools();
const toolsByName = getToolsByName();
// Initialize the LLM
const llm = await initChatModel("openai:gpt-4");
+5 -6
View File
@@ -7,9 +7,9 @@
* @module email_assistant_hitl_memory
*
* @structure
* ┌─────────────────────────────────────────────────────────────────────────┐
* ┌─────────────────────────────────────────────────────────────────────────
* │ Email Assistant with Memory │
* ├─────────────────────────────────────────────────────────────────────────┤
* ├─────────────────────────────────────────────────────────────────────────
* │ COMPONENTS │
* │ - LLM (with tools) : GPT-4o model for decision making │
* │ - Memory System : InMemoryStore for maintaining preferences │
@@ -36,7 +36,7 @@
* │ - llmCallNode() : Creates node for LLM response generation │
* │ - initializeEmailAssistant(): Creates the agent graph with all nodes │
* │ - shouldContinue() : Routes graph based on agent output │
* └─────────────────────────────────────────────────────────────────────────┘
* └─────────────────────────────────────────────────────────────────────────
*/
// LangChain imports for chat models
@@ -56,7 +56,6 @@ import {
addMessages,
} from "@langchain/langgraph";
import { ToolCall } from "@langchain/core/messages/tool";
import { StructuredTool } from "@langchain/core/tools";
// Zod imports
import "@langchain/langgraph/zod";
@@ -166,8 +165,8 @@ const shouldContinue = (state: EmailAgentHITLStateType) => {
*/
export const setupLLMAndTools = async () => {
// Get tools
const tools = await getTools();
const toolsByName = await getToolsByName();
const tools = getTools();
const toolsByName = getToolsByName();
// Initialize the LLM for use with router / structured output
const llm = await initChatModel("openai:gpt-4o");
+5 -5
View File
@@ -34,10 +34,10 @@ export interface GetToolsOptions {
* @param options - Configuration options for tool selection
* @returns Array of StructuredTool instances ready for use with agents
*/
export async function getTools({
export function getTools({
toolNames,
includeGmail = false,
}: GetToolsOptions = {}): Promise<StructuredTool[]> {
}: GetToolsOptions = {}): StructuredTool[] {
// Base tools dictionary - all available tools should be registered here
const allTools: Record<string, StructuredTool> = {
write_email: writeEmail,
@@ -68,10 +68,10 @@ export async function getTools({
* @param tools - Optional array of tools to convert to lookup map
* @returns Record mapping tool names to their corresponding StructuredTool instances
*/
export async function getToolsByName(
export function getToolsByName(
tools?: StructuredTool[],
): Promise<Record<string, StructuredTool>> {
const toolsList = tools || (await getTools());
): Record<string, StructuredTool> {
const toolsList = tools || getTools();
return toolsList.reduce<Record<string, StructuredTool>>((acc, tool) => {
acc[tool.name] = tool;
+1 -1
View File
@@ -1,5 +1,5 @@
import { z } from "zod";
import { DynamicStructuredTool, tool } from "@langchain/core/tools";
import { tool } from "@langchain/core/tools";
const scheduleMeetingSchema = z.object({
title: z.string().describe("Meeting title"),
-3
View File
@@ -1,3 +0,0 @@
import { StructuredTool } from "@langchain/core/tools";
export type ToolsMap = Record<string, StructuredTool>;