我想创建这样一个 python 对象初始化一个属性值怎么写classRunnableConfig(TypedDict,totalFalse):Configuration for a Runnable. !!! note Custom values The TypedDict has totalFalse set intentionally to: - Allow partial configs to be created and merged together via merge_configs - Support config propagation from parent to child runnables via var_child_runnable_config (a ContextVar that automatically passes config down the call stack without explicit parameter passing), where configs are merged rather than replaced !!! example python # Parent sets tags chain.invoke(input, config{tags: [parent]}) # Child automatically inherits and can add: # ensure_config({tags: [child]}) - {tags: [parent, child]} tags:list[str]Tags for this call and any sub-calls (e.g. a Chain calling an LLM). You can use these to filter calls. metadata:dict[str,Any]Metadata for this call and any sub-calls (e.g. a Chain calling an LLM). Keys should be strings, values should be JSON-serializable. callbacks:CallbacksCallbacks for this call and any sub-calls (e.g. a Chain calling an LLM). Tags are passed to all callbacks, metadata is passed to handle*Start callbacks. run_name:strName for the tracer run for this call. Defaults to the name of the class.max_concurrency:int|NoneMaximum number of parallel calls to make. If not provided, defaults to ThreadPoolExecutors default. recursion_limit:intMaximum number of times a call can recurse. If not provided, defaults to 25. configurable:dict[str,Any]Runtime values for attributes previously made configurable on this Runnable, or sub-Runnable objects, through configurable_fields or configurable_alternatives. Check output_schema for a description of the attributes that have been made configurable. run_id:uuid.UUID|NoneUnique identifier for the tracer run for this call. If not provided, a new UUID will be generated. 你想要创建一个RunnableConfig类型的对象并初始化它的属性值我会分步骤教你如何正确实现包括必要的导入和不同的初始化方式。第一步完整的代码准备包含所有必要导入首先需要导入依赖的模块和类型这是创建该对象的前提fromtypingimportTypedDict,Any,OptionalfromuuidimportUUID,uuid4fromlangchain_core.callbacksimportCallbacks# 如果你用的是 langchain 框架# 定义 RunnableConfig 类和你提供的代码一致classRunnableConfig(TypedDict,totalFalse):Configuration for a Runnable.tags:list[str]Tags for this call and any sub-calls (e.g. a Chain calling an LLM).metadata:dict[str,Any]Metadata for this call and any sub-calls (e.g. a Chain calling an LLM).callbacks:CallbacksCallbacks for this call and any sub-calls (e.g. a Chain calling an LLM).run_name:strName for the tracer run for this call.max_concurrency:int|NoneMaximum number of parallel calls to make.recursion_limit:intMaximum number of times a call can recurse.configurable:dict[str,Any]Runtime values for configurable attributes.run_id:UUID|NoneUnique identifier for the tracer run for this call.第二步初始化 RunnableConfig 对象的几种方式因为RunnableConfig是TypedDict类型字典初始化方式和普通字典一致但会有类型提示校验以下是常用的初始化方式方式1基础初始化指定部分属性适合只需要设置部分属性的场景因为totalFalse允许部分初始化# 初始化一个包含 tags、run_name 和 recursion_limit 的配置对象config1:RunnableConfig{tags:[chain_call,llm_invoke],run_name:MyFirstRunnable,recursion_limit:30# 覆盖默认的 25}# 打印验证print(config1)# 输出{tags: [chain_call, llm_invoke], run_name: MyFirstRunnable, recursion_limit: 30}方式2完整属性初始化所有字段适合需要明确设置所有属性的场景# 生成一个 UUID 作为 run_idcustom_run_iduuid4()# 完整初始化config2:RunnableConfig{tags:[full_config,test],metadata:{env:dev,version:1.0.0},callbacks:None,# 实际使用时替换为你的 Callbacks 实例run_name:FullConfigRunnable,max_concurrency:10,recursion_limit:25,configurable:{model_name:gpt-3.5-turbo},run_id:custom_run_id}# 打印验证print(fRun ID:{config2[run_id]})print(fConfigurable model:{config2[configurable][model_name]})方式3动态添加属性初始化后补充因为TypedDict本质是字典也可以先初始化空对象再动态添加属性# 空初始化config3:RunnableConfig{}# 动态添加属性config3[tags][dynamic,example]config3[run_name]DynamicConfigconfig3[max_concurrency]None# 使用默认值# 打印验证print(config3)# 输出{tags: [dynamic, example], run_name: DynamicConfig, max_concurrency: None}关键说明TypedDict 特性totalFalse意味着所有属性都是可选的你不需要初始化所有字段就能创建对象类型校验如果你使用 IDE如 PyCharm、VS Code会自动校验属性的类型比如tags必须是字符串列表run_id必须是 UUID 或 NoneUUID 生成run_id通常用uuid4()生成唯一标识也可以传None让框架自动生成Callbacks 类型Callbacks是 langchain 框架的回调类型实际使用时需要传入具体的回调实例如ConsoleCallbackHandler测试时可以传None。总结创建RunnableConfig对象本质是创建符合类型约束的字典支持部分初始化因totalFalse、完整初始化或动态添加属性初始化时需注意属性类型匹配如tags是list[str]、run_id是UUID | None推荐根据实际需求选择初始化方式只设置需要的属性即可无需冗余配置。