Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

chore: update workforce doc and openai o1 example (#1133)

Wendong-Fan9f589bb4bf85
diff --git a/docs/key_modules/workforce.md b/docs/key_modules/workforce.md
index e6517dbd5..059077a47 100644
--- a/docs/key_modules/workforce.md
+++ b/docs/key_modules/workforce.md
@@ -12,11 +12,12 @@ For more detailed usage information, please refer to our cookbook: [Create A Hac
### Architecture
-Workforce follows a hierarchical architecture. A workforce can consist of
-multiple worker nodes, and each of the worker nodes will contain an agent
-as the worker. The worker nodes are managed by a coordinator agent inside the
-workforce, and the coordinator agent will assign tasks to the worker nodes
-according to the description of the worker nodes, along with their tool sets.
+Workforce follows a hierarchical architecture. A workforce can consist of
+multiple worker nodes, and each of the worker nodes will contain
+one agent or multiple agents as the worker. The worker nodes are managed by
+a coordinator agent inside the workforce, and the coordinator agent will assign
+tasks to the worker nodes according to the description of the worker nodes,
+along with their tool sets.
Alongside the coordinator agent, there is also a task planner agent inside the
workforce. The task planner agent will take the responsibility of decomposing
diff --git a/examples/models/openai_o1_example.py b/examples/models/openai_o1_example.py
index 7dd89a3e6..4d644124b 100644
--- a/examples/models/openai_o1_example.py
+++ b/examples/models/openai_o1_example.py
@@ -14,7 +14,6 @@
from camel.agents import ChatAgent
from camel.configs import ChatGPTConfig
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType
@@ -24,22 +23,151 @@ o1_model = ModelFactory.create(
model_config_dict=ChatGPTConfig(temperature=0.0).as_dict(),
)
-# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
-
# Set agent
-camel_agent = ChatAgent(system_message=sys_msg, model=o1_model)
+camel_agent = ChatAgent(model=o1_model)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Write a bash script that takes a matrix represented as a string
+# Set user message
+user_msg = """Write a bash script that takes a matrix represented as a string
with format '[1,2],[3,4],[5,6]' and prints the transpose in the same
- format.""",
-)
+ format."""
# Get response information
response = camel_agent.step(user_msg)
print(response.msgs[0].content)
+'''
+===============================================================================
+Here's a bash script that transposes a matrix represented as the string format
+specified. It handles matrices of various sizes, including those with varying
+numbers of columns.
+
+```bash
+#!/bin/bash
+
+# Read input string from argument or stdin
+if [ -n "$1" ]; then
+ input="$1"
+else
+ read input
+fi
+
+# Preprocess the input string to facilitate parsing
+# Replace '],[' with '];[' to use ';' as row separator
+input="${input//],[/];[}"
+
+# Remove leading and trailing square brackets if any
+input="${input#[}"
+input="${input%]}"
+
+# Split the input into rows
+IFS=';' read -ra rows <<< "$input"
+
+declare -A matrix
+
+nrows=${#rows[@]}
+ncols=0
+
+# Parse each row
+for ((i=0; i<nrows; i++)); do
+ row="${rows[i]}"
+ # Remove leading '[' and trailing ']'
+ row="${row#[}"
+ row="${row%]}"
+ # Split row into elements
+ IFS=',' read -ra elems <<< "$row"
+ num_elems=${#elems[@]}
+ if (( num_elems > ncols )); then
+ ncols=$num_elems
+ fi
+ # Store elements in matrix associative array
+ for ((j=0; j<num_elems; j++)); do
+ matrix[$i,$j]="${elems[j]}"
+ done
+done
+
+# Function to join array elements with a delimiter
+join_by() {
+ local d=$1; shift
+ if [ "$#" -gt 0 ]; then
+ printf %s "$1" "${@/#/$d}"
+ fi
+}
+
+# Now, build the transposed matrix
+transposed_rows=()
+for ((j=0; j<ncols; j++)); do
+ tr_row_elements=()
+ for ((i=0; i<nrows; i++)); do
+ e="${matrix[$i,$j]:-}" # Use empty string if element is missing
+ tr_row_elements+=("$e")
+ done
+ tr_row_elements_str=$(join_by ',' "${tr_row_elements[@]}")
+ tr_row="[${tr_row_elements_str}]"
+ transposed_rows+=("$tr_row")
+done
+
+# Build output string
+output=$(join_by ',' "${transposed_rows[@]}")
+
+# Print the output
+echo "$output"
+```
+
+**Usage:**
+
+Save the script to a file, for example, `transpose_matrix.sh`, and make it
+executable:
+
+```bash
+chmod +x transpose_matrix.sh
+```
+
+You can run the script by passing the matrix string as an argument:
+
+```bash
+./transpose_matrix.sh '[1,2],[3,4],[5,6]'
+```
+
+Output:
+
+```
+[1,3,5],[2,4,6]
+```
+
+**Explanation:**
+
+The script performs the following steps:
+
+1. **Input Preprocessing:**
+ - Replaces `],[` with `];[` to use `;` as a separator between rows.
+ - Removes any leading or trailing square brackets.
+
+2. **Parsing the Input into a Matrix:**
+ - Splits the input string into rows using `IFS`.
+ - For each row:
+ - Removes the leading `[` and trailing `]`.
+ - Splits the row into its elements.
+ - Stores the elements into an associative array `matrix` with keys as
+ `row,column`.
+
+3. **Determining the Matrix Dimensions:**
+ - Counts the number of rows (`nrows`).
+ - Determines the maximum number of columns (`ncols`) across all rows.
+
+4. **Transposing the Matrix:**
+ - Iterates over each column index.
+ - For each column, collects the elements from each row at that column index.
+ - Builds the transposed row string and adds it to `transposed_rows`.
+
+5. **Generating the Output:**
+ - Joins the transposed rows using commas to form the final output string.
+ - Prints the output.
+
+**Notes:**
+
+- The script supports matrices where rows have different numbers of columns.
+- Missing elements in the matrix (due to irregular column sizes) are handled
+by inserting empty strings in the transposed matrix.
+- The `join_by` function is used to handle joining array elements with a
+specified delimiter, ensuring proper formatting.
+===============================================================================
+'''