Skip to content

Fix FileSurfer to locate and list files #6275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions python/packages/autogen-ext/tests/test_filesurfer_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,55 @@ async def test_file_surfer_serialization() -> None:

# Check that the deserialized agent has the same attributes as the original agent
assert isinstance(deserialized_agent, FileSurfer)


@pytest.mark.asyncio
async def test_open_path_valid_directory(monkeypatch: pytest.MonkeyPatch) -> None:
# Create a test directory
test_dir = os.path.abspath("test_filesurfer_agent_dir")
os.makedirs(test_dir, exist_ok=True)

# Mock the API calls
model = "gpt-4o-2024-05-13"
chat_completions = [
ChatCompletion(
id="id1",
choices=[
Choice(
finish_reason="tool_calls",
index=0,
message=ChatCompletionMessage(
content=None,
tool_calls=[
ChatCompletionMessageToolCall(
id="1",
type="function",
function=Function(
name="open_path",
arguments=json.dumps({"path": test_dir}),
),
)
],
role="assistant",
),
)
],
created=0,
model=model,
object="chat.completion",
usage=CompletionUsage(prompt_tokens=10, completion_tokens=5, total_tokens=0),
),
]
mock = _MockChatCompletion(chat_completions)
monkeypatch.setattr(AsyncCompletions, "create", mock.mock_create)
agent = FileSurfer(
"FileSurfer",
model_client=OpenAIChatCompletionClient(model=model, api_key=""),
)

# Get the FileSurfer to read the directory
assert agent._name == "FileSurfer" # pyright: ignore[reportPrivateUsage]
result = await agent.run(task="Please read the test directory")
assert isinstance(result.messages[1], TextMessage)
assert "# Index of " in result.messages[1].content
assert "test_filesurfer_agent_dir" in result.messages[1].content
Loading