Skip to content

Commit

Permalink
Implement Base of Methodical Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Cormanz committed May 18, 2023
1 parent 4f2117b commit b21a781
Show file tree
Hide file tree
Showing 14 changed files with 1,706 additions and 442 deletions.
1 change: 1 addition & 0 deletions dolly-15k.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
404: Not Found
26 changes: 1 addition & 25 deletions src/auto/agents/employee/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,5 @@ pub fn use_tool(
let agent = get_agent(context);
agent.llm.clear_history();

if action.tool == "google_search" {
agent.llm.message_history.push(Message::System(format!(
"Rewrite the information provided by the google search into this format:
### [WEBSITE NAME](WEBSITE URL)
[WEBSITE SNIPPET]
Ensure it is readable and compressed."
)));
} else if action.tool == "browse_url" {
return Ok(out);
} else {
agent.llm.message_history.push(Message::System(format!(
"Rewrite the information provided by the tool below into a readable and simple Markdown representation.
Ensure all of the information is included.
Keep your response at one or two paragraphs.
Remember that if returns 'null', the command was successful and just has no output."
)));
}

agent.llm.message_history.push(Message::User(out));

println!("{}", "Processing Command Output...".yellow());

agent.llm.model.get_response_sync(&agent.llm.get_messages(), Some(600), None)
return Ok(out);
}
103 changes: 103 additions & 0 deletions src/auto/agents/employee/methodical.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use std::error::Error;

use serde::{Serialize, Deserialize};

use crate::{CommandContext, AgentInfo, Message, auto::{try_parse_json, run::Action}};

use super::log_yaml;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct MethodicalThoughts {
pub thoughts: String,
pub action: Action
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct MethodicalAction {
pub tool: String,
pub purpose: String
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct MethodicalStep {
pub idea: String,
pub action: MethodicalAction
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct MethodicalPlan {
pub steps: Vec<MethodicalStep>
}

pub fn run_method_agent(
context: &mut CommandContext,
get_agent: &impl Fn(&mut CommandContext) -> &mut AgentInfo,
task: &str,
first_inst: bool
) -> Result<String, Box<dyn Error>> {
let agent = get_agent(context);

if first_inst {
agent.llm.prompt.push(Message::User(format!(r#"
Tools:
google_search {{ "query": "..." }}
browse_urls {{ "urls": [ "..." ] }}
file_append {{ "path": "...", "content": "..." }}
You have been given these tools.
Task:
Research at least three articles on M&M health detriments.
Create a list of steps.
Each step will use one tool.
Then, describe each time you will use the tool (i.e. browsing multiple articles)
Do not specify arguments.
Respond in this JSON format:
```json
{{
"steps": [
{{
"idea": "idea",
"action": {{
"tool": "tool",
"purpose": "purpose"
}}
}}
]
}}
```
"#)));
}

let plan = try_parse_json::<MethodicalPlan>(&agent.llm, 2, Some(300))?;
agent.llm.prompt.push(Message::Assistant(plan.raw));
let plan = plan.data;
log_yaml(&plan)?;



for step in plan.steps {
let step_text = serde_yaml::to_string(&step)?;

agent.llm.prompt.push(Message::User(format!(r#"
You have created a plan.
Now you will carry out the first step:
{step_text}
Respond in this JSON format:
```json
{{
"thoughts: "thoughts",
"action": {{
"tool": "tool",
"args": {{ ... }}
}}
}}
```
"#)))
}

Ok("No".to_string())
}
10 changes: 5 additions & 5 deletions src/auto/agents/employee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ use super::findings::get_observations;
mod actor;
mod react;
mod refine;
mod planner;
mod methodical;

pub use actor::*;
pub use react::*;
pub use refine::*;
pub use planner::*;
pub use methodical::*;

pub fn run_employee<T>(program: &mut ProgramInfo, task: &str, end: impl Fn(&mut AgentInfo) -> T) -> Result<T, Box<dyn Error>> {
let mut context = program.context.lock().unwrap();

let refine_info = refine(&mut context, &|context| &mut context.agents.planner, task)?;
/*let refine_info = refine(&mut context, &|context| &mut context.agents.planner, task)?;
log_yaml(&refine_info)?;
let task = &refine_info.task;
let task = &refine_info.task;*/

let response = run_planner_agent(&mut context, task)?;
let response = run_method_agent(&mut context, &|ctx| &mut ctx.agents.react, task, true)?;
println!("{response}");

panic!("T");
Expand Down
160 changes: 0 additions & 160 deletions src/auto/agents/employee/planner.rs

This file was deleted.

Loading

0 comments on commit b21a781

Please sign in to comment.