Skip to content

Commit

Permalink
Share a thread again
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Oct 7, 2024
1 parent 973309c commit f7d563d
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/chatbot/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,14 @@ async def schedule_memories(state: ChatState, config: RunnableConfig) -> None:
"""Prompt the bot to respond to the user, incorporating memories (if provided)."""
configurable = ChatConfigurable.from_runnable_config(config)
memory_client = get_client()
mem_thread_id = str(
uuid.uuid5(
uuid.NAMESPACE_URL,
configurable.mem_assistant_id + config["configurable"]["thread_id"],
)
)
await memory_client.threads.create(thread_id=mem_thread_id, if_exists="do_nothing")
await memory_client.runs.create(
# Generate a thread so we can run the memory service on a separate
# but consistent thread. This lets us cancel scheduled runs if
# a new message arrives to our chatbot before the memory service
# begins processing.
thread_id=mem_thread_id,
# We enqueue the memory formation process on the same thread.
# This means that IF this thread doesn't receive more messages before `after_seconds`,
# it will read from the shared state and extract memories for us.
# If a new request comes in for this thread before the scheduled run is executed,
# that run will be canceled, and a **new** one will be scheduled once
# this node is executed again.
thread_id=config["configurable"]["thread_id"],
# Rollback & cancel any scheduled runs for the target thread
# that haven't completed
multitask_strategy="rollback",
Expand Down

0 comments on commit f7d563d

Please sign in to comment.