Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ After Phase 3 is resolved, implement in this order.
- [ ] 4.2 — Implement `ToolDefinition.from(...)` overloads ([#1840](https://github.com/github/copilot-sdk/issues/1840))
- [X] 4.3 — Implement schema and coercion internals ([#1841](https://github.com/github/copilot-sdk/issues/1841))
- [X] 4.4 — Unit tests for API behavior and validation ([#1842](https://github.com/github/copilot-sdk/issues/1842))
- [ ] 4.5 — E2E integration test ([#1843](https://github.com/github/copilot-sdk/issues/1843))
- [X] 4.5 — E2E integration test ([#1843](https://github.com/github/copilot-sdk/issues/1843))
- [ ] 4.6 — Documentation updates ([#1844](https://github.com/github/copilot-sdk/issues/1844))

### 4.1 — Add public API types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.copilot.rpc.SessionConfig;
import com.github.copilot.rpc.ToolDefinition;
import com.github.copilot.rpc.ToolSet;
import com.github.copilot.tool.Param;

/**
* Failsafe integration test for the ergonomic {@code @CopilotTool} +
Expand Down Expand Up @@ -82,4 +83,49 @@ void ergonomicToolDefinition() throws Exception {
}
}
}

@Test
void lambdaToolDefinition() throws Exception {
ctx.configureForTest("tools", "ergonomic_tool_definition");

class LambdaTools {
String currentPhase;
}
LambdaTools tools = new LambdaTools();

ToolDefinition setCurrentPhase = ToolDefinition.from("set_current_phase", "Sets the current phase of the agent",
Param.of(String.class, "phase", "The phase to transition to"), phase -> {
tools.currentPhase = phase;
return "Phase set to " + phase;
});

ToolDefinition searchItems = ToolDefinition.from("search_items", "Search for items by keyword",
Param.of(String.class, "keyword", "Search keyword"),
keyword -> "Found: " + keyword + " -> item_alpha, item_beta");

try (CopilotClient client = ctx.createClient()) {
CopilotSession session = client
.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setAvailableTools(new ToolSet().addCustom("*").addBuiltIn("web_fetch"))
.setTools(List.of(setCurrentPhase, searchItems)))
.get(30, TimeUnit.SECONDS);

try {
AssistantMessageEvent response = session.sendAndWait(new MessageOptions().setPrompt(
"First, set the current phase to 'analyzing'. Then search for items with keyword 'copilot'. Report the phase and search results."),
60_000).get(90, TimeUnit.SECONDS);

assertNotNull(response, "Expected a response from the assistant");
String content = response.getData().content().toLowerCase();
assertTrue(content.contains("analyzing"),
"Response should contain the updated phase: " + response.getData().content());
assertTrue(content.contains("item_alpha") || content.contains("item_beta"),
"Response should contain search results: " + response.getData().content());
assertTrue("analyzing".equals(tools.currentPhase),
"Expected currentPhase to be 'analyzing' but was: " + tools.currentPhase);
} finally {
session.close();
}
}
}
}
Loading