Skip to content

Commit 86cb20d

Browse files
committed
Fix harvesting logic in tools.py
1 parent 366323a commit 86cb20d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

examples/sugarscrap_g1mt/tools.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
if TYPE_CHECKING:
1111
from mesa_llm.llm_agent import LLMAgent
1212

13-
if TYPE_CHECKING:
14-
from mesa_llm.llm_agent import LLMAgent
15-
1613

1714
@tool(tool_manager=trader_tool_manager)
1815
def move_to_best_resource(agent: "LLMAgent") -> str:
@@ -80,12 +77,21 @@ def propose_trade(
8077
)
8178

8279
if other_agent is None:
83-
return f"Agent {other_agent} not found."
80+
return f"Agent {other_agent_id} not found."
8481

8582
if not isinstance(other_agent, Trader):
8683
return f"agent {other_agent_id} is not a valid trader."
8784

8885
# Simple trade acceptance logic for demonstration
86+
if sugar_amount <= 0 or spice_amount <= 0:
87+
return "sugar_amount and spice_amount must be positive."
88+
89+
if agent.sugar < sugar_amount or other_agent.spice < spice_amount:
90+
return (
91+
f"agent {agent.unique_id} or agent {other_agent_id} "
92+
"does not have enough resources for this trade."
93+
)
94+
8995
if other_agent.calculate_mrs() > agent.calculate_mrs():
9096
agent.sugar -= sugar_amount
9197
agent.spice += spice_amount

0 commit comments

Comments
 (0)