ccm commited on
Commit
50178ea
·
1 Parent(s): a7ba1f0

Updated beam agent.

Browse files
agents/agent_with_custom_beam_design_tools.py CHANGED
@@ -1,14 +1,14 @@
1
  import os
 
2
 
3
  import smolagents
4
  import smolagents.tools
5
 
 
6
  # Rectangular section properties tool
7
  class RectSectionPropsTool(smolagents.tools.Tool):
8
  name = "rect_section_props"
9
- description = (
10
- "Rectangular section properties."
11
- )
12
  inputs = {
13
  "b": {"type": "number", "description": "Width in meters"},
14
  "h": {"type": "number", "description": "Height in meters"},
@@ -20,15 +20,14 @@ class RectSectionPropsTool(smolagents.tools.Tool):
20
  raise ValueError("b and h must be positive.")
21
  A = b * h
22
  I = b * (h**3) / 12.0
23
- S = I / (h / 2.0) # = b*h^2/6
24
  return {"A": A, "I": I, "S": S}
25
 
 
26
  # Circle section properties tool
27
  class CircleSectionPropsTool(smolagents.tools.Tool):
28
  name = "circle_section_props"
29
- description = (
30
- "Circular section properties."
31
- )
32
  inputs = {
33
  "d": {"type": "number", "description": "Diameter in meters"},
34
  }
@@ -39,20 +38,21 @@ class CircleSectionPropsTool(smolagents.tools.Tool):
39
  raise ValueError("d must be positive.")
40
  A = math.pi * (d**2) / 4.0
41
  I = math.pi * (d**4) / 64.0
42
- S = I / (d / 2.0) # = π d^3 / 32
43
  return {"A": A, "I": I, "S": S}
44
 
45
 
46
  # Mass tool
47
  class BeamMassTool(smolagents.tools.Tool):
48
  name = "beam_mass"
49
- description = (
50
- "Beam mass [kg]."
51
- )
52
  inputs = {
53
  "L": {"type": "number", "description": "Length in meters"},
54
  "rho": {"type": "number", "description": "Material density in kg/m^3"},
55
- "A": {"type": "number", "description": "Cross-sectional area in m^2 (optional)"},
 
 
 
56
  }
57
  output_type = "number"
58
 
@@ -61,40 +61,29 @@ class BeamMassTool(smolagents.tools.Tool):
61
  raise ValueError("L, rho, and A must be positive.")
62
  return rho * A * L
63
 
 
64
  # Deflection tool
65
  class BeamDeflectionTool(smolagents.tools.Tool):
66
  name = "beam_deflection"
67
- description = (
68
- "Max deflection δ [m] for simple cases."
69
- )
70
  inputs = {
71
  "P": {"type": "number", "description": "Point load in Newtons"},
72
  "L": {"type": "number", "description": "Span length in meters"},
73
  "E": {"type": "number", "description": "Young's modulus in Pascals"},
74
  "I": {"type": "number", "description": "Second moment in m^4 (optional)"},
75
- "bc": {"type": "string", "description": "Boundary case: 'cantilever_end' or 'ss_center'"},
76
  }
77
  output_type = "number"
78
 
79
- def forward(self, P: float, L: float, E: float, bc: str, I: float) -> float:
80
  if any(x <= 0 for x in [P, L, E, I]):
81
  raise ValueError("P, L, E, I must be positive.")
82
- key = str(bc).lower().strip()
83
- if key in ["cantilever", "cantilever_end", "cantilver_end", "cantilever-tip", "cantilever_tip"]:
84
- return P * (L**3) / (3.0 * E * I)
85
- elif key in ["ss", "ss_center", "simply_supported_center", "simply supported center", "simply_supported"]:
86
- return P * (L**3) / (48.0 * E * I)
87
- else:
88
- raise ValueError("Unsupported bc. Use 'cantilever_end' or 'ss_center'.")
89
-
90
 
91
 
92
  # Bending stress tool
93
  class BeamBendingStressTool(smolagents.tools.Tool):
94
  name = "beam_bending_stress"
95
- description = (
96
- "Max bending stress σ_max [Pa]."
97
- )
98
  inputs = {
99
  "M": {"type": "number", "description": "Bending moment in N·m"},
100
  "I": {"type": "number", "description": "Second moment in m^4 (optional)"},
@@ -105,7 +94,8 @@ class BeamBendingStressTool(smolagents.tools.Tool):
105
  def forward(self, M: float, I: float, c: float) -> float:
106
  if M <= 0:
107
  raise ValueError("M must be positive.")
108
- return M *c/I
 
109
 
110
  def generate_beam_agent() -> smolagents.CodeAgent:
111
  # Define the agent with all of these tools.
@@ -122,7 +112,8 @@ def generate_beam_agent() -> smolagents.CodeAgent:
122
  api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
123
  api_key=os.getenv("OPENAI_API_KEY"),
124
  ),
 
125
  name="BeamAgent",
126
  add_base_tools=False,
127
  max_steps=12,
128
- )
 
1
  import os
2
+ import math
3
 
4
  import smolagents
5
  import smolagents.tools
6
 
7
+
8
  # Rectangular section properties tool
9
  class RectSectionPropsTool(smolagents.tools.Tool):
10
  name = "rect_section_props"
11
+ description = "Rectangular section properties."
 
 
12
  inputs = {
13
  "b": {"type": "number", "description": "Width in meters"},
14
  "h": {"type": "number", "description": "Height in meters"},
 
20
  raise ValueError("b and h must be positive.")
21
  A = b * h
22
  I = b * (h**3) / 12.0
23
+ S = I / (h / 2.0) # = b*h^2/6
24
  return {"A": A, "I": I, "S": S}
25
 
26
+
27
  # Circle section properties tool
28
  class CircleSectionPropsTool(smolagents.tools.Tool):
29
  name = "circle_section_props"
30
+ description = "Circular section properties."
 
 
31
  inputs = {
32
  "d": {"type": "number", "description": "Diameter in meters"},
33
  }
 
38
  raise ValueError("d must be positive.")
39
  A = math.pi * (d**2) / 4.0
40
  I = math.pi * (d**4) / 64.0
41
+ S = I / (d / 2.0) # = π d^3 / 32
42
  return {"A": A, "I": I, "S": S}
43
 
44
 
45
  # Mass tool
46
  class BeamMassTool(smolagents.tools.Tool):
47
  name = "beam_mass"
48
+ description = "Beam mass [kg]."
 
 
49
  inputs = {
50
  "L": {"type": "number", "description": "Length in meters"},
51
  "rho": {"type": "number", "description": "Material density in kg/m^3"},
52
+ "A": {
53
+ "type": "number",
54
+ "description": "Cross-sectional area in m^2 (optional)",
55
+ },
56
  }
57
  output_type = "number"
58
 
 
61
  raise ValueError("L, rho, and A must be positive.")
62
  return rho * A * L
63
 
64
+
65
  # Deflection tool
66
  class BeamDeflectionTool(smolagents.tools.Tool):
67
  name = "beam_deflection"
68
+ description = "Max deflection δ [m] for simple cases."
 
 
69
  inputs = {
70
  "P": {"type": "number", "description": "Point load in Newtons"},
71
  "L": {"type": "number", "description": "Span length in meters"},
72
  "E": {"type": "number", "description": "Young's modulus in Pascals"},
73
  "I": {"type": "number", "description": "Second moment in m^4 (optional)"},
 
74
  }
75
  output_type = "number"
76
 
77
+ def forward(self, P: float, L: float, E: float, I: float) -> float:
78
  if any(x <= 0 for x in [P, L, E, I]):
79
  raise ValueError("P, L, E, I must be positive.")
80
+ return P * (L**3) / (3.0 * E * I)
 
 
 
 
 
 
 
81
 
82
 
83
  # Bending stress tool
84
  class BeamBendingStressTool(smolagents.tools.Tool):
85
  name = "beam_bending_stress"
86
+ description = "Max bending stress σ_max [Pa]."
 
 
87
  inputs = {
88
  "M": {"type": "number", "description": "Bending moment in N·m"},
89
  "I": {"type": "number", "description": "Second moment in m^4 (optional)"},
 
94
  def forward(self, M: float, I: float, c: float) -> float:
95
  if M <= 0:
96
  raise ValueError("M must be positive.")
97
+ return M * c / I
98
+
99
 
100
  def generate_beam_agent() -> smolagents.CodeAgent:
101
  # Define the agent with all of these tools.
 
112
  api_base=os.getenv("UPSTREAM_OPENAI_BASE", "").rstrip("/"),
113
  api_key=os.getenv("OPENAI_API_KEY"),
114
  ),
115
+ instructions="You are a beam design agent with custom tools to support that task. Use those tools whenever feasible.",
116
  name="BeamAgent",
117
  add_base_tools=False,
118
  max_steps=12,
119
+ )