mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
refactor: replace bare dict with ActionDict TypedDict in cot_agent_runner (#34997)
This commit is contained in:
parent
44ebfa3bb8
commit
602753b68a
@ -2,7 +2,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Generator, Mapping, Sequence
|
from collections.abc import Generator, Mapping, Sequence
|
||||||
from typing import Any
|
from typing import Any, TypedDict
|
||||||
|
|
||||||
from graphon.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta, LLMUsage
|
from graphon.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta, LLMUsage
|
||||||
from graphon.model_runtime.entities.message_entities import (
|
from graphon.model_runtime.entities.message_entities import (
|
||||||
@ -29,6 +29,13 @@ from models.model import Message
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ActionDict(TypedDict):
|
||||||
|
"""Shape produced by AgentScratchpadUnit.Action.to_dict()."""
|
||||||
|
|
||||||
|
action: str
|
||||||
|
action_input: dict[str, Any] | str
|
||||||
|
|
||||||
|
|
||||||
class CotAgentRunner(BaseAgentRunner, ABC):
|
class CotAgentRunner(BaseAgentRunner, ABC):
|
||||||
_is_first_iteration = True
|
_is_first_iteration = True
|
||||||
_ignore_observation_providers = ["wenxin"]
|
_ignore_observation_providers = ["wenxin"]
|
||||||
@ -331,7 +338,7 @@ class CotAgentRunner(BaseAgentRunner, ABC):
|
|||||||
|
|
||||||
return tool_invoke_response, tool_invoke_meta
|
return tool_invoke_response, tool_invoke_meta
|
||||||
|
|
||||||
def _convert_dict_to_action(self, action: dict) -> AgentScratchpadUnit.Action:
|
def _convert_dict_to_action(self, action: ActionDict) -> AgentScratchpadUnit.Action:
|
||||||
"""
|
"""
|
||||||
convert dict to action
|
convert dict to action
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user