Sdílet prostřednictvím


Session

AgentSession je kontejner stavu konverzace používaný napříč spuštěními agenta.

Co AgentSession obsahuje

Pole Účel
session_id Místní jedinečný identifikátor pro tuto relaci
service_session_id Identifikátor konverzace vzdálené služby (při použití historie spravované službou)
state Proměnlivý slovník sdílený s poskytovateli kontextu/historie

Předdefinovaný vzor použití

AgentSession session = await agent.CreateSessionAsync();

var first = await agent.RunAsync("My name is Alice.", session);
var second = await agent.RunAsync("What is my name?", session);
session = agent.create_session()

first = await agent.run("My name is Alice.", session=session)
second = await agent.run("What is my name?", session=session)

Vytvoření relace z existujícího ID konverzace služby

Tuto možnost použijte, pokud již backingová služba má stav konverzace.

session = agent.get_session(service_session_id="<service-conversation-id>")
response = await agent.run("Continue this conversation.", session=session)

Serializace a obnovení

var serialized = agent.SerializeSession(session);
AgentSession resumed = await agent.DeserializeSessionAsync(serialized);
serialized = session.to_dict()
resumed = AgentSession.from_dict(serialized)

Důležité

Relace jsou specifické pro konkrétní agenty a služby. Opětovné použití relace s jinou konfigurací agenta nebo poskytovatelem může vést k neplatnému kontextu.

Další kroky