Skip to content

Commit 80aafbb

Browse files
Reverting copilot fix.
1 parent ad24eea commit 80aafbb

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

src/smolagents/bp_tools.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,12 @@ def _session_config(self):
14621462
"on_permission_request": PermissionHandler.approve_all,
14631463
}
14641464

1465-
def _ensure_client(self):
1466-
"""Lazily start a background event loop and copilot client (no session)."""
1465+
def _ensure_session(self):
1466+
"""Lazily start a background event loop, copilot client, and session.
1467+
1468+
Uses PermissionHandler.approve_all to grant copilot full access to
1469+
its built-in tools (file read/write, shell, URL fetch, etc.).
1470+
"""
14671471
if self._loop is None:
14681472
import asyncio
14691473
import threading
@@ -1484,27 +1488,22 @@ def _ensure_client(self):
14841488
async def _init():
14851489
self._client = CopilotClient()
14861490
await self._client.start()
1491+
self._session = await self._client.create_session(self._session_config())
14871492
self._run_async(_init())
14881493

1489-
def _ensure_session(self):
1490-
"""Ensure client is started and a session exists."""
1491-
self._ensure_client()
1492-
if self._session is None:
1493-
self._reset_session()
1494-
14951494
def _reset_session(self):
14961495
"""Create a fresh copilot session (drops conversation history).
14971496
14981497
Reuses the existing client and event loop; only the session is replaced.
14991498
"""
15001499
async def _reset():
1501-
self._session = await self._client.create_session(**self._session_config())
1500+
self._session = await self._client.create_session(self._session_config())
15021501
self._run_async(_reset())
15031502

15041503
def forward(self, task_str: str, restart_chat: bool = True) -> str:
1505-
self._ensure_client()
1504+
self._ensure_session()
15061505

1507-
if restart_chat or self._session is None:
1506+
if restart_chat and self._session is not None:
15081507
self._reset_session()
15091508

15101509
prompt = (task_str)

0 commit comments

Comments
 (0)