Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions crates/forge_app/src/service/system_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl PromptService for Live {
files.sort();

let ctx = SystemContext {
env: self.env.clone(),
tool_information: self.tool.usage_prompt(),
tool_supported,
env: Some(self.env.clone()),
tool_information: Some(self.tool.usage_prompt()),
tool_supported: Some(tool_supported),
custom_instructions,
files,
};
Expand Down
6 changes: 3 additions & 3 deletions crates/forge_app/src/service/workflow_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ impl Live {
tool: ToolDefinition,
) -> Result<String> {
let ctx = SystemContext {
tool_information: tool.usage_prompt().to_string(),
tool_supported,
env: Environment::default(),
tool_information: Some(tool.usage_prompt().to_string()),
tool_supported: Some(tool_supported),
env: Some(Environment::default()),
custom_instructions: None,
files: vec![],
};
Expand Down
60 changes: 48 additions & 12 deletions crates/forge_domain/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ use derive_more::derive::Display;
use derive_setters::Setters;
use handlebars::Handlebars;
use schemars::schema::RootSchema;
use serde::Serialize;
use serde::{Deserialize, Serialize};

use crate::variables::Variables;
use crate::{Environment, Error, ModelId, Provider, ToolName};
use crate::{Environment, Error, ModelId, Provider, ToolDefinition, ToolName};

#[derive(Serialize, Setters, Clone)]
#[derive(Default, Setters, Clone, Serialize, Deserialize)]
#[setters(strip_option)]
pub struct SystemContext {
pub env: Environment,
pub tool_information: String,
pub tool_supported: bool,
pub env: Option<Environment>,
pub tool_information: Option<String>,
pub tool_supported: Option<bool>,
pub custom_instructions: Option<String>,
pub files: Vec<String>,
}
Expand All @@ -23,6 +24,7 @@ pub enum PromptContent {
File(PathBuf),
}

#[derive(Clone, Serialize, Deserialize)]
pub struct Prompt<V> {
pub template: PromptTemplate,
pub variables: Schema<V>,
Expand All @@ -39,35 +41,69 @@ impl<V: Serialize> Prompt<V> {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Schema<S> {
pub schema: RootSchema,
_marker: std::marker::PhantomData<S>,
}

#[derive(Clone, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PromptTemplate(String);
impl PromptTemplate {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}

#[derive(Debug, Display, Eq, PartialEq, Hash, Clone)]
#[derive(Debug, Display, Eq, PartialEq, Hash, Clone, Serialize, Deserialize)]
#[serde(transparent)]
pub struct AgentId(String);

impl From<ToolName> for AgentId {
fn from(value: ToolName) -> Self {
Self(value.into_string())
}
}

#[derive(Clone, Serialize, Deserialize)]
pub struct Agent {
pub id: AgentId,
pub provider: Provider,
pub model: ModelId,
pub description: String,
pub system_prompt: Prompt<SystemContext>,
pub user_prompt: Prompt<Variables>,

/// Suggests if the agent needs to maintain its state for the lifetime of
/// the program.
pub ephemeral: bool,

/// Tools that the agent can use
pub tools: Vec<ToolName>,
pub transforms: Vec<Transform>,

/// Downstream agents that this agent can handover to
pub handovers: Vec<Downstream>,

/// Represents that the agent is the entry point to the workflow
pub entry: bool,
}

impl From<Agent> for ToolDefinition {
fn from(value: Agent) -> Self {
ToolDefinition {
name: ToolName::new(value.id.0),
description: value.description,
input_schema: value.user_prompt.variables.schema,
output_schema: None,
}
}
}

/// Transformations that can be applied to the agent's context before sending it
/// upstream to the provider.
#[derive(Clone, Serialize, Deserialize)]
pub enum Transform {
/// Compresses multiple assistant messages into a single message
Assistant {
Expand All @@ -89,8 +125,8 @@ pub enum Transform {
Tap { agent_id: AgentId, input: String },
}

impl Agent {
pub fn new(_name: impl Into<String>) -> Self {
todo!()
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Downstream {
pub agent: AgentId,
pub wait: bool,
}
40 changes: 0 additions & 40 deletions crates/forge_domain/src/arena.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/forge_domain/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::path::PathBuf;

use async_trait::async_trait;
use derive_setters::Setters;
use serde::Serialize;
use serde::{Deserialize, Serialize};

#[derive(Default, Serialize, Debug, Setters, Clone)]
#[derive(Default, Debug, Setters, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[setters(strip_option)]
/// Represents the environment in which the application is running.
Expand Down
8 changes: 4 additions & 4 deletions crates/forge_domain/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::pin::Pin;

use thiserror::Error;

use crate::{AgentId, WorkflowId};
use crate::AgentId;

// NOTE: Deriving From for error is a really bad idea. This is because you end
// up converting errors incorrectly without much context. For eg: You don't want
Expand All @@ -28,11 +28,11 @@ pub enum Error {
#[error("Agent not found in the arena: {0}")]
AgentUndefined(AgentId),

#[error("Workflow not found in the arena: {0}")]
WorkflowUndefined(WorkflowId),

#[error("Variable not found in output: {0}")]
UndefinedVariable(String),

#[error("Head agent not found")]
HeadAgentUndefined,
}

pub type Result<A> = std::result::Result<A, Error>;
Expand Down
1 change: 0 additions & 1 deletion crates/forge_domain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod agent;
mod arena;
mod chat_request;
mod chat_response;
mod chat_stream_ext;
Expand Down
1 change: 1 addition & 0 deletions crates/forge_domain/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Usage {
#[setters(into, strip_option)]
pub struct ChatCompletionMessage {
pub content: Option<Content>,
// TODO: rename to tool_calls (plural)
pub tool_call: Vec<ToolCall>,
pub finish_reason: Option<FinishReason>,
pub usage: Option<Usage>,
Expand Down
Loading