Skip to content

Commit 1268526

Browse files
committed
Output tool execution result in logs
1 parent edaa5ce commit 1268526

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/regent/span.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ def log_operation(live: true, &block)
8585
result = yield
8686

8787
@end_time = live ? Time.now.freeze : @end_time
88+
update_message_with_result(result) if type == Type::TOOL_EXECUTION
8889
logger.success(label: type, **({ duration: duration.round(2), meta: meta }.merge(arguments)))
89-
9090
result
9191
end
92+
93+
def update_message_with_result(message)
94+
arguments[:message] = "#{arguments[:message]}#{message}"
95+
end
9296
end
9397
end

spec/regent/agent_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,45 @@ def call(query)
101101
expect(agent.session.spans[3].type).to eq(Regent::Span::Type::LLM_CALL)
102102
expect(agent.session.spans.last.type).to eq(Regent::Span::Type::ANSWER)
103103
end
104+
105+
context "logging" do
106+
before do
107+
allow(TTY::Spinner).to receive(:new).and_return(spinner)
108+
end
109+
110+
it "logs steps in the console" do
111+
agent.run("What is the price of Bitcoin?")
112+
113+
# Input
114+
expect(spinner).to have_received(:update).with(
115+
title: /\[.*?INPUT.*?\].*?What is the price of Bitcoin\?/
116+
).exactly(2).times
117+
118+
# LLM Call
119+
expect(spinner).to have_received(:update).with(
120+
title: /\[.*?LLM.*?❯.*?gpt-4o-mini.*?\].*?What is the price of Bitcoin\?/
121+
).exactly(2).times
122+
123+
# Tool Execution - Initial call
124+
expect(spinner).to have_received(:update).with(
125+
title: /\[.*?TOOL.*?❯.*?price_tool.*?\].*?:.*?\["Bitcoin"\](?:\e\[0m)?$/
126+
).once
127+
128+
# Tool Execution - Result
129+
expect(spinner).to have_received(:update).with(
130+
title: /\[.*?TOOL.*?❯.*?price_tool.*?\[.*?0\.\d*s.*?\].*?:.*?\["Bitcoin"\] → {'BTC': '\$107,000', 'ETH': '\$6,000'}\e\[0m/
131+
).once
132+
133+
expect(spinner).to have_received(:update).with(
134+
title: /\[.*?LLM.*?❯.*?gpt-4o-mini.*?\].*?Observation:/
135+
).exactly(2).times
136+
137+
# Answer
138+
expect(spinner).to have_received(:update).with(
139+
title: /\[.*?ANSWER.*?❯.*?success.*?\].*?The price of Bitcoin is \$107,000\./
140+
).exactly(2).times
141+
end
142+
end
104143
end
105144
end
106145

0 commit comments

Comments
 (0)