Skip to content

Commit d265959

Browse files
author
Abhishek Singh
committed
Merge branch 'main' into abhi/feat/auth
Signed-off-by: Abhishek Singh <abhishek.s@in.ibm.com>
2 parents f86803a + edc4ae9 commit d265959

File tree

6 files changed

+176
-64
lines changed

6 files changed

+176
-64
lines changed

agents/official/beeai-framework/chat/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ authors = [
77
]
88
requires-python = ">=3.13,<4"
99
dependencies = [
10-
"beeai-framework[duckduckgo,wikipedia]~=0.1.34",
10+
"beeai-framework[duckduckgo,wikipedia]~=0.1.35",
1111
"beeai-sdk",
12-
"openinference-instrumentation-beeai>=0.1.6",
12+
"openinference-instrumentation-beeai>=0.1.7",
1313
"pydantic-settings>=2.9.0",
1414
"sqlalchemy>=2.0.41",
1515
"uvicorn>=0.35.0",

agents/official/beeai-framework/chat/src/chat/agent.py

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
)
2525
from beeai_framework.agents.experimental.utils._tool import FinalAnswerTool
2626
from beeai_framework.backend.types import ChatModelParameters
27+
from beeai_framework.emitter import EventMeta
2728
from beeai_framework.memory import UnconstrainedMemory
2829
from beeai_framework.middleware.trajectory import GlobalTrajectoryMiddleware
2930
from beeai_framework.tools import Tool
3031
from beeai_framework.tools.search.duckduckgo import DuckDuckGoSearchTool
3132
from beeai_framework.tools.search.wikipedia import WikipediaTool
32-
from beeai_framework.tools.weather.openmeteo import OpenMeteoTool
33+
34+
from beeai_framework.tools.weather import OpenMeteoTool
35+
3336
from beeai_sdk.a2a.extensions import (
3437
AgentDetail,
3538
AgentDetailTool,
@@ -41,8 +44,7 @@
4144
from beeai_sdk.a2a.types import AgentMessage
4245
from beeai_sdk.server import Server
4346
from beeai_sdk.server.context import Context
44-
from openinference.instrumentation.beeai import BeeAIInstrumentor
45-
47+
from chat.tools.general.current_time import CurrentTimeTool
4648
from chat.helpers.citations import extract_citations
4749
from chat.helpers.trajectory import TrajectoryContent
4850
from chat.tools.files.file_creator import FileCreatorTool, FileCreatorToolOutput
@@ -57,12 +59,18 @@
5759
ClarificationTool,
5860
clarification_tool_middleware,
5961
)
60-
from chat.tools.general.current_time import CurrentTimeTool
62+
63+
# Temporary instrument fix
64+
EventMeta.model_fields["context"].exclude = True
6165

6266
BeeAIInstrumentor().instrument()
6367
## TODO: https://github.com/phoenixframework/phoenix/issues/6224
64-
logging.getLogger("opentelemetry.exporter.otlp.proto.http._log_exporter").setLevel(logging.CRITICAL)
65-
logging.getLogger("opentelemetry.exporter.otlp.proto.http.metric_exporter").setLevel(logging.CRITICAL)
68+
logging.getLogger("opentelemetry.exporter.otlp.proto.http._log_exporter").setLevel(
69+
logging.CRITICAL
70+
)
71+
logging.getLogger("opentelemetry.exporter.otlp.proto.http.metric_exporter").setLevel(
72+
logging.CRITICAL
73+
)
6674

6775
logger = logging.getLogger(__name__)
6876

@@ -86,13 +94,36 @@
8694
user_greeting="How can I help you?",
8795
tools=[
8896
AgentDetailTool(
89-
name="Web Search (DuckDuckGo)",
90-
description="Retrieves real-time search results.",
97+
name="Act Tool",
98+
description="Auxiliary tool that ensures thoughtful tool selection by requiring explicit reasoning and tool choice before executing any other tool.",
99+
),
100+
AgentDetailTool(
101+
name="Clarification Tool",
102+
description="Enables the agent to ask clarifying questions when user requirements are unclear, preventing assumptions and ensuring accurate task completion.",
103+
),
104+
AgentDetailTool(
105+
name="Wikipedia Search",
106+
description="Fetches summaries and information from Wikipedia articles.",
91107
),
92-
AgentDetailTool(name="Wikipedia Search", description="Fetches summaries from Wikipedia."),
93108
AgentDetailTool(
94109
name="Weather Information (OpenMeteo)",
95-
description="Provides real-time weather updates.",
110+
description="Provides real-time weather updates and forecasts.",
111+
),
112+
AgentDetailTool(
113+
name="Web Search (DuckDuckGo)",
114+
description="Retrieves real-time search results from the web.",
115+
),
116+
AgentDetailTool(
117+
name="File Reader",
118+
description="Reads and returns content from uploaded or generated files.",
119+
),
120+
AgentDetailTool(
121+
name="File Creator",
122+
description="Creates new files with specified content and metadata, uploading them to the platform for download or further processing.",
123+
),
124+
AgentDetailTool(
125+
name="Current Time",
126+
description="Provides current date and time information.",
96127
),
97128
],
98129
framework="BeeAI",
@@ -129,7 +160,9 @@
129160
"""
130161
),
131162
tags=["chat"],
132-
examples=["Please find a room in LA, CA, April 15, 2025, checkout date is april 18, 2 adults"],
163+
examples=[
164+
"Please find a room in LA, CA, April 15, 2025, checkout date is april 18, 2 adults"
165+
],
133166
)
134167
],
135168
)
@@ -143,7 +176,9 @@ async def chat(
143176
The agent is an AI-powered conversational system with memory, supporting real-time search, Wikipedia lookups,
144177
and weather updates through integrated tools.
145178
"""
146-
extracted_files = await extract_files(history=messages[context.context_id], incoming_message=message)
179+
extracted_files = await extract_files(
180+
history=messages[context.context_id], incoming_message=message
181+
)
147182
input = to_framework_message(message)
148183

149184
# Configure tools
@@ -153,12 +188,12 @@ async def chat(
153188

154189
FinalAnswerTool.description = """Assemble and send the final answer to the user. When using information gathered from other tools that provided URL addresses, you MUST properly cite them using markdown citation format: [description](URL).
155190
156-
Citation Requirements:
191+
# Citation Requirements:
157192
- Use descriptive text that summarizes the source content
158193
- Include the exact URL provided by the tool
159194
- Place citations inline where the information is referenced
160195
161-
Examples:
196+
# Examples:
162197
- According to [OpenAI's latest announcement](https://example.com/gpt5), GPT-5 will be released next year.
163198
- Recent studies show [AI adoption has increased by 67%](https://example.com/ai-study) in enterprise environments.
164199
- Weather data indicates [temperatures will reach 25°C tomorrow](https://weather.example.com/forecast).""" # type: ignore
@@ -185,6 +220,7 @@ async def chat(
185220
api_key=os.getenv("LLM_API_KEY", "dummy"),
186221
base_url=os.getenv("LLM_API_BASE", "http://localhost:11434/v1"),
187222
parameters=ChatModelParameters(temperature=0.0),
223+
tool_choice_support=set(),
188224
)
189225

190226
# Create agent
@@ -194,7 +230,7 @@ async def chat(
194230
memory=UnconstrainedMemory(),
195231
requirements=requirements,
196232
middlewares=[
197-
GlobalTrajectoryMiddleware(included=[Tool]),
233+
GlobalTrajectoryMiddleware(included=[Tool]), # ChatModel,
198234
act_tool_middleware,
199235
clarification_tool_middleware,
200236
],
@@ -252,14 +288,20 @@ async def chat(
252288

253289
message = AgentMessage(
254290
text=clean_text,
255-
metadata=(citation.citation_metadata(citations=citations) if citations else None),
291+
metadata=(
292+
citation.citation_metadata(citations=citations) if citations else None
293+
),
256294
)
257295
messages[context.context_id].append(message)
258296
yield message
259297

260298

261299
def serve():
262-
server.run(host=os.getenv("HOST", "127.0.0.1"), port=int(os.getenv("PORT", 8000)), configure_telemetry=True)
300+
server.run(
301+
host=os.getenv("HOST", "127.0.0.1"),
302+
port=int(os.getenv("PORT", 8000)),
303+
configure_telemetry=True,
304+
)
263305

264306

265307
if __name__ == "__main__":

agents/official/beeai-framework/chat/src/chat/tools/files/file_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FileCreatorTool(
3838
Creates a new file and writes the provided content into it.
3939
"""
4040

41-
name: str = "FileCreator"
41+
name: str = "file_creator"
4242
description: str = "Create a new file with the specified content."
4343
input_schema: type[FileCreatorInput] = FileCreatorInput
4444

agents/official/beeai-framework/chat/src/chat/tools/general/act.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from beeai_framework.context import RunContext
1616
from beeai_framework.emitter import Emitter, EventMeta
1717
from beeai_framework.tools import (
18+
AnyTool,
1819
JSONToolOutput,
1920
Tool,
2021
ToolInputValidationError,
@@ -133,9 +134,16 @@ class ActAlwaysFirstRequirement(Requirement[RequirementAgentRunState]):
133134

134135
name: str = "act_always_first"
135136

137+
tools: list[AnyTool] = []
138+
139+
async def init(self, *, tools: list[AnyTool], ctx: RunContext) -> None:
140+
await super().init(tools=tools, ctx=ctx)
141+
self.tools = tools
142+
136143
@run_with_context
137144
async def run(self, state: RequirementAgentRunState, ctx: RunContext) -> list[Rule]:
138145
last_step = state.steps[-1] if state.steps else None
146+
139147
if last_step and last_step.tool and last_step.tool.name == "act":
140148
assert isinstance(last_step.tool, ActTool)
141149
if last_step.error is not None:
@@ -162,14 +170,27 @@ async def run(self, state: RequirementAgentRunState, ctx: RunContext) -> list[Ru
162170
)
163171
]
164172

173+
# Hide all tools except ActTool on the first step
174+
rules = [
175+
Rule(
176+
target=t.name,
177+
hidden=True,
178+
allowed=False,
179+
prevent_stop=False,
180+
forced=False,
181+
)
182+
for t in self.tools
183+
if not isinstance(t, ActTool)
184+
]
165185
return [
166186
Rule(
167187
target="act",
168188
forced=True,
169189
allowed=True,
170190
prevent_stop=False,
171191
hidden=False,
172-
)
192+
),
193+
*rules,
173194
]
174195

175196

agents/official/beeai-framework/chat/src/chat/tools/general/current_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CurrentTimeTool(Tool[CurrentTimeToolInput]):
2121
def input_schema(self) -> type[CurrentTimeToolInput]:
2222
return CurrentTimeToolInput
2323

24-
def _run(
24+
async def _run(
2525
self,
2626
input: CurrentTimeToolInput,
2727
options: ToolRunOptions | None,

0 commit comments

Comments
 (0)