Files
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

42 lines
1.3 KiB
Python

import os
from aworld.agents.llm_agent import Agent
from aworld.config.conf import AgentConfig
from aworld.core.task import Task
from aworld.runner import Runners
from aworld.config import RunConfig, EngineName
# Setup, need modify
os.environ["LLM_PROVIDER"] = "openai"
os.environ["LLM_MODEL_NAME"] = "gpt-4o"
os.environ["LLM_API_KEY"] = "your-api-key"
# os.environ["LLM_BASE_URL"] = "https://api.openai.com/v1"
# Create agent
agent_config = AgentConfig(
llm_provider=os.getenv("LLM_PROVIDER", "openai"),
llm_model_name=os.getenv("LLM_MODEL_NAME"),
llm_api_key=os.getenv("LLM_API_KEY"),
# llm_base_url=os.getenv("LLM_BASE_URL")
)
my_agent = Agent(name="my_agent", conf=agent_config)
# Create tasks
tasks = [
Task(input="What is machine learning?", agent=my_agent, id="task1"),
Task(input="Explain neural networks", agent=my_agent, id="task2"),
Task(input="What is deep learning?", agent=my_agent, id="task3")
]
# Run in parallel (default local run).
# If you want to run in a distributed environment, you need to submit a job to the Ray cluster.
results = Runners.sync_run_task(
task=tasks,
run_conf=RunConfig(
engine_name=EngineName.RAY,
worker_num=len(tasks)
)
)
# Process results
for task_id, result in results.items():
print(f"Task {task_id}: {result.answer}")