使用场景
探索 Dynamic Context 的实际用例,并了解它如何提升对话中的角色响应性、相关性和上下文感知能力。
初学者
个性化对话
using System.Collections;
using Convai.Runtime.Components;
using Convai.Runtime.Room;
using UnityEngine;
/// <summary>
/// 在会话开始时将玩家身份注入到活动的 Convai 会话中。
/// 角色在第一次交流之前会收到这些上下文,并且可以
/// 无需在控制台重新配置,就直接用玩家的名字和职业打招呼。
/// </summary>
public class PlayerGreeting : MonoBehaviour
{
[SerializeField] private string _playerName = "Aria";
[SerializeField] private string _playerClass = "游侠";
private IConvaiRoomConnectionService _connectionService;
private IEnumerator Start()
{
while (true)
{
ConvaiManager manager = ConvaiManager.ActiveManager;
if (manager != null && manager.TryGetRoomConnectionService(out _connectionService))
break;
yield return null;
}
if (_connectionService.IsConnected)
SendGreeting();
else
_connectionService.Connected += OnConnected;
}
private void OnConnected()
{
_connectionService.Connected -= OnConnected;
SendGreeting();
}
private void SendGreeting()
{
string context =
$"你正在与 {_playerName} 交谈,他/她是一名 1 级 {_playerClass}。 " +
"热情地问候他们,并欢迎他们来到这个世界。";
// replace — 确保不会沿用上一次会话中的旧上下文。
// runLlm: true — 会触发即时的问候回复。
bool sent = _connectionService.UpdateDynamicContext(context, mode: "replace", runLlm: "true");
if (!sent)
Debug.LogWarning("[PlayerGreeting] UpdateDynamicContext 返回 false。");
}
private void OnDestroy()
{
if (_connectionService != null)
_connectionService.Connected -= OnConnected;
}
}注入学习者档案
模块推进
语言导师熟练度等级
注入情绪状态
中级
响应式游戏状态
静默事件累积
由表现驱动的辅导难度
分支式合规情景状态
医疗模拟患者生命体征监测
高级
跨场景能力差距追踪器
实时程序化评估
具有自主响应阈值的反应式角色
最后更新于
这有帮助吗?