Default state value idea #2047
bluemeat0724
started this conversation in
Discussions
Replies: 1 comment 1 reply
-
I was hoping to incorporate more logic into the Pydantic model. Will such features be supported in the future? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Are there good ways to manupulate state value.
Here is what I tried to set up default state:
class GraphState(BaseModel):
sys_msg: Optional[str] = 'You are a helpful assistant'
messages: Annotated[list[AnyMessage], add_messages]
def node(state: GraphState):
return {"messages": [{'role':"user","content":"just add something",'name':'G'}]}
builder = StateGraph(GraphState)
builder.add_node(node)
builder.add_edge(START, "node")
builder.add_edge("node", END)
graph = builder.compile()
graph.invoke({"messages": "hello"})
expect:
{'sys_msg': 'You are a helpful assistant',
'messages': [HumanMessage(content='hello', additional_kwargs={}, response_metadata={}, id='5aa8a2b4-77c3-46df-b2c5-14adc3ca3d54'),
HumanMessage(content='just add something', additional_kwargs={}, response_metadata={}, name='G', id='888011a5-8ca7-4ebf-aed1-fe88f096adbc')]}
got:
{'messages': [HumanMessage(content='hello', additional_kwargs={}, response_metadata={}, id='76912a86-3ffb-4e92-9e3d-2cb77a6430fc'),
HumanMessage(content='just add something', additional_kwargs={}, response_metadata={}, name='G', id='eaf45e81-0067-45e6-b58f-c65bb180e41f')]}
Beta Was this translation helpful? Give feedback.
All reactions