mirror of
https://github.com/block/goose.git
synced 2026-04-28 11:39:43 +00:00
Use Instructions as Prompt in Scheduler (#5359)
This commit is contained in:
parent
53391f2065
commit
0ca4e0ba4e
1 changed files with 54 additions and 57 deletions
|
|
@ -655,7 +655,9 @@ impl Scheduler {
|
||||||
schedule_sessions.push((session.id.clone(), session));
|
schedule_sessions.push((session.id.clone(), session));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schedule_sessions.sort_by(|a, b| b.0.cmp(&a.0));
|
|
||||||
|
// Sort by created_at timestamp, newest first
|
||||||
|
schedule_sessions.sort_by(|a, b| b.1.created_at.cmp(&a.1.created_at));
|
||||||
|
|
||||||
let result_sessions: Vec<(String, Session)> =
|
let result_sessions: Vec<(String, Session)> =
|
||||||
schedule_sessions.into_iter().take(limit).collect();
|
schedule_sessions.into_iter().take(limit).collect();
|
||||||
|
|
@ -1171,14 +1173,10 @@ async fn run_scheduled_job_internal(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create session upfront for both cases
|
// Create session upfront
|
||||||
let session = match SessionManager::create_session(
|
let session = match SessionManager::create_session(
|
||||||
current_dir.clone(),
|
current_dir.clone(),
|
||||||
if recipe.prompt.is_some() {
|
format!("Scheduled job: {}", job.id),
|
||||||
format!("Scheduled job: {}", job.id)
|
|
||||||
} else {
|
|
||||||
"Empty job - no prompt".to_string()
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
@ -1199,65 +1197,64 @@ async fn run_scheduled_job_internal(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref prompt_text) = recipe.prompt {
|
// Use prompt if available, otherwise fall back to instructions
|
||||||
let mut conversation =
|
let prompt_text = recipe
|
||||||
Conversation::new_unvalidated(vec![Message::user().with_text(prompt_text.clone())]);
|
.prompt
|
||||||
|
.as_ref()
|
||||||
|
.or(recipe.instructions.as_ref())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let session_config = SessionConfig {
|
let mut conversation =
|
||||||
id: session.id.clone(),
|
Conversation::new_unvalidated(vec![Message::user().with_text(prompt_text.clone())]);
|
||||||
working_dir: current_dir.clone(),
|
|
||||||
schedule_id: Some(job.id.clone()),
|
|
||||||
execution_mode: job.execution_mode.clone(),
|
|
||||||
max_turns: None,
|
|
||||||
retry_config: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
match agent
|
let session_config = SessionConfig {
|
||||||
.reply(conversation.clone(), Some(session_config.clone()), None)
|
id: session.id.clone(),
|
||||||
.await
|
working_dir: current_dir.clone(),
|
||||||
{
|
schedule_id: Some(job.id.clone()),
|
||||||
Ok(mut stream) => {
|
execution_mode: job.execution_mode.clone(),
|
||||||
use futures::StreamExt;
|
max_turns: None,
|
||||||
|
retry_config: None,
|
||||||
|
};
|
||||||
|
|
||||||
while let Some(message_result) = stream.next().await {
|
match agent
|
||||||
tokio::task::yield_now().await;
|
.reply(conversation.clone(), Some(session_config.clone()), None)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(mut stream) => {
|
||||||
|
use futures::StreamExt;
|
||||||
|
|
||||||
match message_result {
|
while let Some(message_result) = stream.next().await {
|
||||||
Ok(AgentEvent::Message(msg)) => {
|
tokio::task::yield_now().await;
|
||||||
if msg.role == rmcp::model::Role::Assistant {
|
|
||||||
tracing::info!("[Job {}] Assistant: {:?}", job.id, msg.content);
|
match message_result {
|
||||||
}
|
Ok(AgentEvent::Message(msg)) => {
|
||||||
conversation.push(msg);
|
if msg.role == rmcp::model::Role::Assistant {
|
||||||
}
|
tracing::info!("[Job {}] Assistant: {:?}", job.id, msg.content);
|
||||||
Ok(AgentEvent::McpNotification(_)) => {}
|
|
||||||
Ok(AgentEvent::ModelChange { .. }) => {}
|
|
||||||
Ok(AgentEvent::HistoryReplaced(updated_conversation)) => {
|
|
||||||
conversation = updated_conversation;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
tracing::error!(
|
|
||||||
"[Job {}] Error receiving message from agent: {}",
|
|
||||||
job.id,
|
|
||||||
e
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
conversation.push(msg);
|
||||||
|
}
|
||||||
|
Ok(AgentEvent::McpNotification(_)) => {}
|
||||||
|
Ok(AgentEvent::ModelChange { .. }) => {}
|
||||||
|
Ok(AgentEvent::HistoryReplaced(updated_conversation)) => {
|
||||||
|
conversation = updated_conversation;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!(
|
||||||
|
"[Job {}] Error receiving message from agent: {}",
|
||||||
|
job.id,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
return Err(JobExecutionError {
|
|
||||||
job_id: job.id.clone(),
|
|
||||||
error: format!("Agent failed to reply for recipe '{}': {}", job.source, e),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
Err(e) => {
|
||||||
tracing::warn!(
|
return Err(JobExecutionError {
|
||||||
"[Job {}] Recipe '{}' has no prompt to execute.",
|
job_id: job.id.clone(),
|
||||||
job.id,
|
error: format!("Agent failed to reply for recipe '{}': {}", job.source, e),
|
||||||
job.source
|
});
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = SessionManager::update_session(&session.id)
|
if let Err(e) = SessionManager::update_session(&session.id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue