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
45 changes: 45 additions & 0 deletions crates/goose-server/src/routes/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use goose::config::Config;
use goose::config::PermissionManager;
use goose::model::ModelConfig;
use goose::providers::create;
use goose::recipe::Response;
use goose::{
agents::{extension::ToolInfo, extension_manager::get_parameter_names},
config::permission::PermissionLevel,
Expand Down Expand Up @@ -62,6 +63,11 @@ struct UpdateProviderRequest {
model: Option<String>,
}

#[derive(Deserialize)]
struct SessionConfigRequest {
response: Option<Response>,
}

#[derive(Deserialize)]
pub struct GetToolsQuery {
extension_name: Option<String>,
Expand Down Expand Up @@ -262,6 +268,44 @@ async fn update_router_tool_selector(
))
}

#[utoipa::path(
post,
path = "/agent/session_config",
responses(
(status = 200, description = "Session config updated successfully", body = String),
(status = 500, description = "Internal server error")
)
)]
async fn update_session_config(
State(state): State<Arc<AppState>>,
headers: HeaderMap,
Json(payload): Json<SessionConfigRequest>,
) -> Result<Json<String>, Json<ErrorResponse>> {
verify_secret_key(&headers, &state).map_err(|_| {
Json(ErrorResponse {
error: "Unauthorized - Invalid or missing API key".to_string(),
})
})?;

let agent = state.get_agent().await.map_err(|e| {
tracing::error!("Failed to get agent: {}", e);
Json(ErrorResponse {
error: format!("Failed to get agent: {}", e),
})
})?;

if let Some(response) = payload.response {
agent.add_final_output_tool(response).await;

tracing::info!("Added final output tool with response config");
Ok(Json(
"Session config updated with final output tool".to_string(),
))
} else {
Ok(Json("Nothing provided to update.".to_string()))
}
}

pub fn routes(state: Arc<AppState>) -> Router {
Router::new()
.route("/agent/versions", get(get_versions))
Expand All @@ -273,5 +317,6 @@ pub fn routes(state: Arc<AppState>) -> Router {
"/agent/update_router_tool_selector",
post(update_router_tool_selector),
)
.route("/agent/session_config", post(update_session_config))
.with_state(state)
}
4 changes: 3 additions & 1 deletion crates/goose/src/agents/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,9 @@ mod tests {
agent.add_final_output_tool(response).await;

let tools = agent.list_tools(None).await;
let final_output_tool = tools.iter().find(|tool| tool.name == "final_output");
let final_output_tool = tools
.iter()
.find(|tool| tool.name == FINAL_OUTPUT_TOOL_NAME);

assert!(
final_output_tool.is_some(),
Expand Down
2 changes: 1 addition & 1 deletion crates/goose/src/agents/final_output_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mcp_core::{
};
use serde_json::Value;

pub const FINAL_OUTPUT_TOOL_NAME: &str = "final_output";
pub const FINAL_OUTPUT_TOOL_NAME: &str = "recipe__final_output";
pub const FINAL_OUTPUT_CONTINUATION_MESSAGE: &str =
"You MUST call the `final_output` tool with your final output for the user.";

Expand Down
3 changes: 3 additions & 0 deletions ui/desktop/src/components/ToolCallWithResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ function ToolCallView({
}
break;

case 'final_output':
return 'final output';

case 'computer_control':
return 'poking around...';

Expand Down
21 changes: 21 additions & 0 deletions ui/desktop/src/utils/providerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export const initializeSystem = async (
// Get recipeConfig directly here
const recipeConfig = window.appConfig?.get?.('recipeConfig');
const botPrompt = (recipeConfig as { instructions?: string })?.instructions;
const responseConfig = (recipeConfig as { response?: { json_schema?: unknown } })?.response;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you have to add response attribute on the RecipeConfig interface on the client side, and populate to the object when parsing the deeplink.

If you have tested this and it is works, that means my statement above is wrong :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it works, recipeConfig gets populated early in the process, its pretty cryptic.


// Extend the system prompt with desktop-specific information
const response = await fetch(getApiUrl('/agent/prompt'), {
method: 'POST',
Expand All @@ -162,6 +164,25 @@ export const initializeSystem = async (
}
}

// Configure session with response config if present
if (responseConfig?.json_schema) {
const sessionConfigResponse = await fetch(getApiUrl('/agent/session_config'), {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we move this api call to another module? the function is getting longer :)

method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Secret-Key': getSecretKey(),
},
body: JSON.stringify({
response: responseConfig,
}),
});
if (!sessionConfigResponse.ok) {
console.warn(`Failed to configure session: ${sessionConfigResponse.statusText}`);
} else {
console.log('Configured session with response schema');
}
}

if (!options?.getExtensions || !options?.addExtension) {
console.warn('Extension helpers not provided in alpha mode');
return;
Expand Down
Loading