https://github.com/poneding/agent-demo
AI Agent demo.
https://github.com/poneding/agent-demo
Last synced: 12 months ago
JSON representation
AI Agent demo.
- Host: GitHub
- URL: https://github.com/poneding/agent-demo
- Owner: poneding
- Created: 2025-05-29T05:03:13.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-29T05:06:25.000Z (about 1 year ago)
- Last Synced: 2025-05-29T06:21:46.926Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 95.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# agent-demo
1. 初始化一个项目:
```bash
uv init agent-demo && cd agent-demo
uv add dotenv pydantic-ai
```
2. 编辑 *main.py*:
```python
from dotenv import load_dotenv
from pydantic_ai.agent import Agent
from pydantic_ai.models.gemini import GeminiModel
load_dotenv()
model = GeminiModel(model_name="gemini-2.0-flash")
# Emulate a tool function
def say_hello(name: str) -> str:
"""Greet to my good friend."""
return f"Hello, my good friend {name}! -- From the agent-demo"
agent = Agent(
model=model,
system_prompt="You are an expert in Python programming.",
tools=[say_hello], # Add your tools here, generally a list of functions
)
def main():
history_messages = []
while True:
user_input = input("Input: ")
if user_input.lower() in ["exit", "quit"]:
print("Exiting the agent.")
break
response = agent.run_sync(user_input, message_history=history_messages)
history_messages = list(response.all_messages())
print(response.output)
if __name__ == "__main__":
main()
```
3. 创建 .env 文件并配置 GEMINI_API_KEY 环境变量
4. 运行:
```bash
uv run mian.py
```
5. 输入 *Greet to my good friend Jay Chou.*
6. 效果如下:
