mirror of
https://github.com/langchain-ai/agents-from-scratch-ts.git
synced 2026-06-30 21:37:54 -04:00
Cleanup
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
@@ -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,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"),
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { StructuredTool } from "@langchain/core/tools";
|
||||
|
||||
export type ToolsMap = Record<string, StructuredTool>;
|
||||
Reference in New Issue
Block a user