2
2
import json
3
3
from typing import Optional , List , Any , Union , AsyncGenerator , Generator
4
4
5
- from fastapi .responses import StreamingResponse
6
-
7
- from langgraph .graph .graph import CompiledGraph
5
+ from langgraph .graph .state import CompiledStateGraph
8
6
from langchain .schema import BaseMessage , SystemMessage
9
7
from langchain_core .runnables import RunnableConfig , ensure_config
10
8
from langchain_core .messages import HumanMessage
78
76
]
79
77
80
78
class LangGraphAgent :
81
- def __init__ (self , * , name : str , graph : CompiledGraph , description : Optional [str ] = None , config : Union [Optional [RunnableConfig ], dict ] = None ):
79
+ def __init__ (self , * , name : str , graph : CompiledStateGraph , description : Optional [str ] = None , config : Union [Optional [RunnableConfig ], dict ] = None ):
82
80
self .name = name
83
81
self .description = description
84
82
self .graph = graph
85
83
self .config = config or {}
86
84
self .messages_in_process : MessagesInProgressRecord = {}
87
85
self .active_run : Optional [RunMetadata ] = None
86
+ self .constant_schema_keys = ['messages' , 'tools' ]
88
87
89
88
def _dispatch_event (self , event : ProcessedEvents ) -> str :
90
89
return event # Fallback if no encoder
@@ -352,7 +351,6 @@ def set_message_in_progress(self, run_id: str, data: MessageInProgress):
352
351
}
353
352
354
353
def get_schema_keys (self , config ) -> SchemaKeys :
355
- CONSTANT_KEYS = ['messages' ]
356
354
try :
357
355
input_schema = self .graph .get_input_jsonschema (config )
358
356
output_schema = self .graph .get_output_jsonschema (config )
@@ -363,14 +361,14 @@ def get_schema_keys(self, config) -> SchemaKeys:
363
361
config_schema_keys = list (config_schema ["properties" ].keys ()) if "properties" in config_schema else []
364
362
365
363
return {
366
- "input" : [* input_schema_keys , * CONSTANT_KEYS ],
367
- "output" : [* output_schema_keys , * CONSTANT_KEYS ],
364
+ "input" : [* input_schema_keys , * self . constant_schema_keys ],
365
+ "output" : [* output_schema_keys , * self . constant_schema_keys ],
368
366
"config" : config_schema_keys ,
369
367
}
370
368
except Exception :
371
369
return {
372
- "input" : CONSTANT_KEYS ,
373
- "output" : CONSTANT_KEYS ,
370
+ "input" : self . constant_schema_keys ,
371
+ "output" : self . constant_schema_keys ,
374
372
"config" : [],
375
373
}
376
374
0 commit comments