Skip to content

Commit fdaf032

Browse files
committed
feat: 통관진행조회 반환타입 수정 (str->progress_details)
1 parent 62eae73 commit fdaf032

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

app/service.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ def run_model(question: str) -> "Response":
88
ex : "안녕, 너는 뭘 할 수 있어?"
99
예시 코드는 아래와 같습니다.
1010
"""
11-
reply = run_customs_agent(question)
11+
state = run_customs_agent(question)
1212
return Response(
13-
reply=reply,
13+
reply=state.get("final_response"),
14+
progress_details=state.get("progress_details"),
15+
error_reason=state.get("error_reason"),
1416
success=True
1517
)

core/customs_tracking/agent/customs_tracking_agent.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from langchain.agents import create_openai_functions_agent, AgentExecutor
22
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
33

4+
from core.customs_tracking.dto.cargo_progress_result import CargoProgressResult
45
from core.customs_tracking.tools.get_cargo_progress_details import get_cargo_progress_details_by_bl, get_cargo_progress_details_by_mt
56
from core.shared.states.states import CustomsAgentState
67
from core.shared.utils.llm import get_llm
@@ -14,7 +15,7 @@ def customs_tracking_agent(state: CustomsAgentState) -> CustomsAgentState:
1415
("system", """
1516
당신은 통관 및 배송 추적 전문가입니다.
1617
사용할 수 있는 도구 목록이 아래 제공됩니다.
17-
18+
1819
다음 사용자 쿼리를 분석하여 정확히 하나의 카테고리로 분류해주세요:
1920
1. get_cargo_progress_details_by_mt: 화물번호를 통한 통관 진행 조회
2021
2. get_cargo_progress_details_by_bl: 연도, MBL, HBL 번호를 통한 통관 진행 조회
@@ -29,12 +30,32 @@ def customs_tracking_agent(state: CustomsAgentState) -> CustomsAgentState:
2930
tools=tools,
3031
prompt=prompt
3132
)
32-
agent_executor = AgentExecutor(agent=agent, tools=tools)
33+
34+
agent_executor = AgentExecutor(
35+
agent=agent,
36+
tools=tools,
37+
handle_parsing_errors=True,
38+
return_intermediate_steps=True
39+
)
3340

3441
result = agent_executor.invoke({
3542
"input": state["query"],
3643
"messages": state["messages"]
3744
})
3845

39-
state["final_response"] = result["output"]
46+
steps = result.get("intermediate_steps", [])
47+
if steps:
48+
_, tool_result = steps[-1]
49+
# tool_result가 dict라면 아래처럼 처리
50+
if isinstance(tool_result, CargoProgressResult):
51+
state["progress_details"] = tool_result.progress_details
52+
state["error_reason"] = tool_result.error_reason
53+
else:
54+
state["progress_details"] = None
55+
state["error_reason"] = None
56+
57+
state["final_response"] = ""
58+
else:
59+
state["final_response"] = result["output"]
60+
4061
return state

core/graphs/runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from core.shared.states.states import CustomsAgentState
55

66

7-
def run_customs_agent(query: str) -> str:
7+
def run_customs_agent(query: str) -> CustomsAgentState:
88
"""관세청 에이전트를 실행합니다."""
99

1010
# 그래프 생성
@@ -16,10 +16,12 @@ def run_customs_agent(query: str) -> str:
1616
query=query,
1717
intent=None,
1818
final_response="",
19-
intermediate_results={}
19+
intermediate_results={},
20+
error_reason=None,
21+
progress_details=None
2022
)
2123

2224
# 그래프 실행
2325
result = app.invoke(initial_state)
2426

25-
return result["final_response"]
27+
return result

core/shared/states/states.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# 상태 정의
22
from typing import List, Optional, Literal, Dict, Any
3+
34
from typing_extensions import TypedDict
45

56
from langchain_core.messages import BaseMessage
67

8+
from core.customs_tracking.dto.progress_detail import ProgressDetail
79

810
class CustomsAgentState(TypedDict):
911
"""관세청 에이전트 상태"""
1012
messages: List[BaseMessage]
1113
query: str
1214
intent: Optional[Literal["customs_tracking", "tariff_prediction", "qna"]]
1315
final_response: str
14-
intermediate_results: Dict[str, Any]
16+
intermediate_results: Dict[str, Any]
17+
progress_details: Optional[List[ProgressDetail]]
18+
error_reason: Optional[str]

0 commit comments

Comments
 (0)