66
77from application .agents .base import BaseAgent
88from application .agents .tool_executor import ToolExecutor
9- from application .agents .agentic_agent import _sources_have_directory_structure
109from application .agents .tools .internal_search import (
1110 INTERNAL_TOOL_ID ,
12- build_internal_tool_config ,
13- build_internal_tool_entry ,
11+ add_internal_search_tool ,
1412)
1513from application .agents .tools .think import THINK_TOOL_ENTRY , THINK_TOOL_ID
1614from application .logging import LogContext
@@ -130,6 +128,7 @@ def __init__(
130128 self .citations = CitationManager ()
131129 self ._start_time : float = 0
132130 self ._tokens_used : int = 0
131+ self ._last_token_snapshot : int = 0
133132
134133 # ------------------------------------------------------------------
135134 # Budget & timeout helpers
@@ -153,7 +152,9 @@ def _is_over_budget(self) -> bool:
153152 def _snapshot_llm_tokens (self ) -> int :
154153 """Read current token usage from LLM and return delta since last snapshot."""
155154 current = self .llm .token_usage .get ("prompt_tokens" , 0 ) + self .llm .token_usage .get ("generated_tokens" , 0 )
156- return current
155+ delta = current - self ._last_token_snapshot
156+ self ._last_token_snapshot = current
157+ return delta
157158
158159 # ------------------------------------------------------------------
159160 # Main orchestration
@@ -272,21 +273,7 @@ def _setup_tools(self) -> Dict:
272273 """Build tools_dict with user tools + internal search + think."""
273274 tools_dict = self .tool_executor .get_tools ()
274275
275- # Only add internal search if sources are configured
276- source = self .retriever_config .get ("source" , {})
277- has_sources = bool (source .get ("active_docs" ))
278- if self .retriever_config and has_sources :
279- has_dir = _sources_have_directory_structure (source )
280- internal_entry = build_internal_tool_entry (
281- has_directory_structure = has_dir
282- )
283- internal_entry ["config" ] = build_internal_tool_config (
284- ** self .retriever_config ,
285- has_directory_structure = has_dir ,
286- )
287- tools_dict [INTERNAL_TOOL_ID ] = internal_entry
288- elif self .retriever_config and not has_sources :
289- logger .info ("ResearchAgent: No sources configured, skipping internal_search tool" )
276+ add_internal_search_tool (tools_dict , self .retriever_config )
290277
291278 think_entry = dict (THINK_TOOL_ENTRY )
292279 think_entry ["config" ] = {}
@@ -580,7 +567,14 @@ def _execute_step_tools_with_refinement(
580567 call_id = None
581568 while True :
582569 try :
583- next (gen )
570+ event = next (gen )
571+ # Log tool_call status events instead of discarding them
572+ if isinstance (event , dict ) and event .get ("type" ) == "tool_call" :
573+ logger .debug (
574+ "Tool %s status: %s" ,
575+ event .get ("data" , {}).get ("action_name" , "" ),
576+ event .get ("data" , {}).get ("status" , "" ),
577+ )
584578 except StopIteration as e :
585579 result , call_id = e .value
586580 break
0 commit comments