Skip to content

Commit d4cb4c3

Browse files
authored
Merge pull request #16 from hanno-meister/feature/parallel-agent-v2
New Parallel Function Calling Agent with MCP support
2 parents 5906594 + bb605b4 commit d4cb4c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3190
-2303
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ Developping a successful LM application in a profesional context, beyond statele
6161

6262
Synalinks can help you simplify these tasks by leveraging decade old practices in Deep Learning frameworks. We provide a comprehensive suite of tools and features designed to streamline the development process, making it easier to create, evaluate, train, document and deploy robust neuro-symbolic LMs applications.
6363

64+
## What about other frameworks?
65+
66+
<div align="center">
67+
68+
| Framework | MCP | Graph DB | Logical Flow | Robust Branching | Parallel Function Calling | Ease of Use |
69+
| --- | --- | --- | --- | --- | --- | --- |
70+
| Synalinks | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | 😀 |
71+
| DSPy | ✅ Yes | ❌ No | ❌ No | ❌ No | ❌ No | 😢 |
72+
| AdalFlow | ✅ Yes | ❌ No | ❌ No | ❌ No | ❌ No | 😢 |
73+
| TextGrad | ❌ No | ❌ No | ❌ No | ❌ No | ❌ No | 😭 |
74+
| Trace | ❌ No | ❌ No | ❌ No | ❌ No | ❌ No | 😭 |
75+
76+
</div>
77+
6478
## Install
6579

6680
```shell

coverage-badge.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
::: synalinks.src.modules.agents.function_calling_agent

docs/Synalinks API/Modules API/Agents Modules/Parallel ReACT Agent module.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/Synalinks API/Modules API/Agents Modules/ReACT Agent module.md

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Agent Modules
22

3-
- [ReACT module](ReACT Agent module.md)
4-
- [Parallel ReACT module](Parallel ReACT Agent module.md)
3+
- [FunctionCallingAgent module](FunctionCallingAgent module.md)

docs/Synalinks API/Modules API/Core Modules/MultiDecision module.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/Synalinks API/Modules API/Core Modules/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
- [Not module](Not module.md)
66
- [Generator module](Generator module.md)
77
- [Decision module](Decision module.md)
8-
- [MultiDecision module](MultiDecision module.md)
98
- [Action module](Action module.md)
109
- [Branch module](Branch module.md)

docs/Synalinks API/Modules API/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ if __name__ == "__main__":
5252
- [Not module](Core Modules/Not module.md)
5353
- [Generator module](Core Modules/Generator module.md)
5454
- [Decision module](Core Modules/Decision module.md)
55-
- [MultiDecision module](Core Modules/MultiDecision module.md)
5655
- [Action module](Core Modules/Action module.md)
5756
- [Branch module](Core Modules/Branch module.md)
5857

@@ -85,5 +84,4 @@ if __name__ == "__main__":
8584

8685
### Agents Modules
8786

88-
- [ReACT Agent module](Agents Modules/ReACT Agent module.md)
89-
- [Parallel ReACT Agent module](Agents Modules/Parallel ReACT Agent module.md)
87+
- [FunctionCallingAgent module](Agents Modules/FunctionCallingAgent module.md)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import synalinks
2+
import asyncio
3+
import litellm
4+
5+
6+
class Query(synalinks.DataModel):
7+
query: str = synalinks.Field(
8+
description="The user query",
9+
)
10+
11+
12+
class NumericalFinalAnswer(synalinks.DataModel):
13+
final_answer: float = synalinks.Field(
14+
description="The correct final numerical answer",
15+
)
16+
17+
18+
@synalinks.utils.register_synalinks_serializable()
19+
async def calculate(expression: str):
20+
"""Calculate the result of a mathematical expression.
21+
22+
Args:
23+
expression (str): The mathematical expression to calculate, such as
24+
'2 + 2'. The expression can contain numbers, operators (+, -, *, /),
25+
parentheses, and spaces.
26+
"""
27+
if not all(char in "0123456789+-*/(). " for char in expression):
28+
return {
29+
"result": None,
30+
"log": (
31+
"Error: invalid characters in expression. "
32+
"The expression can only contain numbers, operators (+, -, *, /),"
33+
" parentheses, and spaces NOT letters."
34+
),
35+
}
36+
try:
37+
# Evaluate the mathematical expression safely
38+
result = round(float(eval(expression, {"__builtins__": None}, {})), 2)
39+
return {
40+
"result": result,
41+
"log": "Successfully executed",
42+
}
43+
except Exception as e:
44+
return {
45+
"result": None,
46+
"log": f"Error: {e}",
47+
}
48+
49+
50+
async def main():
51+
litellm._turn_on_debug()
52+
language_model = synalinks.LanguageModel(model="ollama/mistral")
53+
54+
tools = [
55+
synalinks.Tool(calculate),
56+
]
57+
58+
inputs = synalinks.Input(data_model=Query)
59+
outputs = await synalinks.FunctionCallingAgent(
60+
data_model=NumericalFinalAnswer,
61+
tools=tools,
62+
language_model=language_model,
63+
max_iterations=5,
64+
return_inputs_with_trajectory=True,
65+
autonomous=True,
66+
)(inputs)
67+
agent = synalinks.Program(
68+
inputs=inputs,
69+
outputs=outputs,
70+
name="math_agent",
71+
description="A math agent",
72+
)
73+
74+
input_query = Query(query="How much is 152648 + 485?")
75+
response = await agent(input_query)
76+
77+
print(response.prettify_json())
78+
79+
if __name__ == "__main__":
80+
asyncio.run(main())

0 commit comments

Comments
 (0)