Skip to content

Commit 994d25f

Browse files
authored
Merge pull request #40 from debuggerone/examples
Add CoT example
2 parents ca3ee2e + e43b118 commit 994d25f

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
AgentM is a library of "Micro Agents" that make it easy to add reliable intelligence to any application. The philosophy behind AgentM is that "Agents" should be mostly comprised of deterministic code with a sprinkle of LLM-powered intelligence mixed in. Many of the existing Agent frameworks place the LLM at the center of the application as an orchestrator that calls a collection of tools. In an AgentM application, your code is the orchestrator, and you only call a micro agent when you need to perform a task that requires intelligence.
44

5-
The initial draft of AgentM was written in JavaScript, but a Python version is available.
5+
Check out the [JavaScript version](https://github.com/Stevenic/agentm-js) to get a sense of AgentM's current feature set.
66

77
## Installation
88

@@ -70,3 +70,35 @@ Grape,Orange
7070
Original list: ['Apple', 'Orange', 'Banana', 'Grape', 'Pineapple']
7171
Sorted list: ['Apple', 'Banana', 'Orange', 'Grape', 'Pineapple']
7272
```
73+
74+
### Example 3: Chain of Thought
75+
76+
Run the **chain of thought** example to see how AgentM solves problems using a step-by-step reasoning approach:
77+
78+
```bash
79+
python examples/chain_of_thought_example.py
80+
```
81+
82+
#### Sample Output:
83+
```bash
84+
Question: What is the square root of 144?
85+
Chain of Thought Reasoning: To find the square root of 144 step-by-step, follow these steps:
86+
87+
1. **Understanding Square Roots**: The square root of a number is a value that, when multiplied by itself, gives that number. For example, if x is the square root of y, then x * x = y.
88+
89+
2. **Identifying the Number**: In this case, we need to find the square root of 144.
90+
91+
3. **Finding Factors**: We'll look for a number that, when multiplied by itself, equals 144.
92+
93+
4. **Testing Numbers**:
94+
- Let's start with smaller numbers:
95+
- 12 * 12 = 144 (this is the answer)
96+
97+
5. **Conclusion**: The square root of 144 is 12.
98+
99+
Thus, the final answer is:
100+
101+
\[
102+
\sqrt{144} = 12
103+
\]
104+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
from core.chain_of_thought_agent import ChainOfThoughtAgent
3+
4+
async def run_chain_of_thought_example():
5+
question = 'What is the square root of 144?'
6+
agent = ChainOfThoughtAgent(question=question)
7+
result = await agent.chain_of_thought()
8+
9+
print("Question:", question)
10+
print("Chain of Thought Reasoning:", result)
11+
12+
if __name__ == "__main__":
13+
asyncio.run(run_chain_of_thought_example())

src/core/chain_of_thought_agent.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import asyncio
2+
from typing import List
3+
from .openai_api import OpenAIClient
4+
5+
class ChainOfThoughtAgent:
6+
def __init__(self, question: str, max_tokens: int = 1000, temperature: float = 0.0):
7+
self.question = question
8+
self.max_tokens = max_tokens
9+
self.temperature = temperature
10+
self.openai_client = OpenAIClient()
11+
12+
async def chain_of_thought(self) -> str:
13+
system_prompt = "You are an assistant tasked with solving problems using the 'chain of thought' reasoning process."
14+
user_prompt = f"Solve the following problem step-by-step: {self.question}"
15+
16+
response = await self.openai_client.complete_chat([
17+
{"role": "system", "content": system_prompt},
18+
{"role": "user", "content": user_prompt}
19+
], max_tokens=self.max_tokens)
20+
21+
return response.strip()

0 commit comments

Comments
 (0)