()
| 100 | """ |
| 101 | |
| 102 | async def main(): |
| 103 | print("\n" + "="*60) |
| 104 | print("MyAgent Demo - Function-based Tools") |
| 105 | print("="*60) |
| 106 | |
| 107 | # 1. 初始化 |
| 108 | model = OpenAIModel( |
| 109 | api_key=os.getenv("OPENAI_API_KEY"), |
| 110 | model_name="gpt-4o", |
| 111 | temperature=0.7 |
| 112 | ) |
| 113 | |
| 114 | agent = MyAgent( |
| 115 | model=model, |
| 116 | config={"name": "my_assistant"} |
| 117 | ) |
| 118 | |
| 119 | print(f"\n✅ Loaded {len(agent.get_registered_tools())} tools") |
| 120 | |
| 121 | # 2. 测试 |
| 122 | tests = [ |
| 123 | "Design a novel organocatalyst for enhancing CO2 conversion in carbon capture processes. The following reference functions are available: 1) Research existing organocatalysts using `query2smiles` to obtain their SMILES structures. 2) Generate structural variants using `modify_mol`. 3) Verify novelty with `patent_check`. Finally, propose a novel organocatalyst with detailed rationale for its design and expected performance. Ensure all steps are documented and justified. ", |
| 124 | # "What's the weather in Beijing?", |
| 125 | # "Calculate (10 + 20) * 3", |
| 126 | # "Get weather for Tokyo and Paris, then calculate the average temperature" |
| 127 | ] |
| 128 | |
| 129 | for i, query in enumerate(tests, 1): |
| 130 | print(f"\n{'─'*60}") |
| 131 | print(f"Test {i}: {query}") |
| 132 | print(f"{'─'*60}") |
| 133 | |
| 134 | result = await agent.execute( |
| 135 | context={"query": query}, |
| 136 | params={"temperature": 0.7} |
| 137 | ) |
| 138 | |
| 139 | if result["status"] == "success": |
| 140 | print(f"\n💬 {result['answer']}") |
| 141 | print(f"\n🔧 Used {len(result['tool_calls'])} tool(s)") |
| 142 | else: |
| 143 | print(f"\n❌ Error: {result['error']}") |
| 144 | |
| 145 | print("\n" + "="*60 + "\n") |
| 146 | |
| 147 | |
| 148 | if __name__ == "__main__": |
no test coverage detected