MCPcopy
hub / github.com/IBM/AssetOpsBench / run

Method run

src/agent/direct_llm_agent/runner.py:80–137  ·  view source on GitHub ↗

Run one direct LLM call and return an AgentResult.

(self, question: str)

Source from the content-addressed store, hash-verified

78 super().__init__(llm, server_paths)
79
80 async def run(self, question: str) -> AgentResult:
81 """Run one direct LLM call and return an AgentResult."""
82 with agent_run_span(
83 "direct-llm-agent",
84 model=self._llm.model_id,
85 question=question,
86 ) as span:
87 started = datetime.now(timezone.utc).isoformat()
88 run_started = time.perf_counter()
89
90 prompt = f"""{_DIRECT_LLM_SYSTEM_PROMPT}
91
92User task:
93{question}
94
95Final answer:"""
96
97 call_started = time.perf_counter()
98 result = self._llm.generate_with_usage(prompt, temperature=0.0)
99 duration_ms = (time.perf_counter() - call_started) * 1000
100 total_duration_ms = (time.perf_counter() - run_started) * 1000
101
102 answer = _clean_final_answer(result.text)
103
104 trajectory = Trajectory(
105 started_at=started,
106 turns=[
107 TurnRecord(
108 index=0,
109 text=answer,
110 tool_calls=[],
111 input_tokens=result.input_tokens,
112 output_tokens=result.output_tokens,
113 duration_ms=duration_ms,
114 )
115 ],
116 )
117
118 span.set_attribute("agent.answer.length", len(answer))
119 span.set_attribute("agent.duration_ms", total_duration_ms)
120 span.set_attribute("agent.llm_time_ms", duration_ms)
121 span.set_attribute("gen_ai.usage.input_tokens", result.input_tokens)
122 span.set_attribute("gen_ai.usage.output_tokens", result.output_tokens)
123 span.set_attribute("agent.tool_calls", 0)
124
125 persist_trajectory(
126 runner_name="direct-llm-agent",
127 model=self._llm.model_id,
128 question=question,
129 answer=answer,
130 trajectory=trajectory,
131 )
132
133 return AgentResult(
134 question=question,
135 answer=answer,
136 trajectory=trajectory,
137 )

Callers 2

_runFunction · 0.95

Calls 7

agent_run_spanFunction · 0.90
persist_trajectoryFunction · 0.90
_clean_final_answerFunction · 0.85
TrajectoryClass · 0.85
TurnRecordClass · 0.85
AgentResultClass · 0.85
generate_with_usageMethod · 0.45