Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose env class to run_agent functions #611

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions paperqa/agents/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async def run_agent(
async def run_fake_agent(
query: QueryRequest,
docs: Docs,
env_class: type[PaperQAEnvironment] = PaperQAEnvironment,
on_env_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_env_step_callback: (
Callable[[list[Message], float, bool, bool], Awaitable] | None
Expand All @@ -151,7 +152,7 @@ async def run_fake_agent(
f"Max timesteps (configured {query.settings.agent.max_timesteps}) is not"
" applicable with the fake agent, ignoring it."
)
env = PaperQAEnvironment(query, docs, **env_kwargs)
env = env_class(query, docs, **env_kwargs)
_, tools = await env.reset()
if on_env_reset_callback:
await on_env_reset_callback(env.state)
Expand Down Expand Up @@ -188,6 +189,7 @@ async def run_aviary_agent(
query: QueryRequest,
docs: Docs,
agent: ToolSelector,
env_class: type[PaperQAEnvironment] = PaperQAEnvironment,
on_env_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_agent_action_callback: (
Callable[[ToolRequestMessage, BaseModel], Awaitable] | None
Expand All @@ -197,7 +199,7 @@ async def run_aviary_agent(
) = None,
**env_kwargs,
) -> tuple[Answer, AgentStatus]:
env = PaperQAEnvironment(query, docs, **env_kwargs)
env = env_class(query, docs, **env_kwargs)
done = False

try:
Expand Down Expand Up @@ -273,14 +275,15 @@ async def run_ldp_agent(
query: QueryRequest,
docs: Docs,
agent: "Agent[SimpleAgentState]",
env_class: type[PaperQAEnvironment] = PaperQAEnvironment,
on_env_reset_callback: Callable[[EnvironmentState], Awaitable] | None = None,
on_agent_action_callback: "Callable[[OpResult[ToolRequestMessage], SimpleAgentState, float], Awaitable] | None" = None, # noqa: E501
on_env_step_callback: (
Callable[[list[Message], float, bool, bool], Awaitable] | None
) = None,
**env_kwargs,
) -> tuple[Answer, AgentStatus]:
env = PaperQAEnvironment(query, docs, **env_kwargs)
env = env_class(query, docs, **env_kwargs)
# NOTE: don't worry about ldp import checks, because we know Settings.make_ldp_agent
# has already taken place, which checks that ldp is installed

Expand Down