feat(agentenv-wrapper): Generic tool-based wrapper for AgentGym environments#6
Closed
feat(agentenv-wrapper): Generic tool-based wrapper for AgentGym environments#6
Conversation
- Add pyproject.toml with package metadata and dependencies - Add README.md with architecture overview and usage examples - Support LangChain integration as optional dependency
- Add ActionTool for representing actions as callable tools - Add ToolDefinition for JSON schema tool definitions - Add ToolResult for execution results with reward/done signals - Add EnvState for environment state representation
- Add BaseToolWrapper abstract base class - Add ToolEnvironmentWrapper for generic AgentEnv servers - Support HTTP-based communication with environment servers - Auto-parse available actions from observations
- Add BabyAIToolWrapper specialized for BabyAI gridworld - Parse BabyAI observations to extract goal and actions - Generate descriptive tool names for dynamic actions - Support render() for visualization
- Add create_langchain_tools() for converting wrapper tools - Add AgentEnvTool extending LangChain BaseTool - Add create_agent_for_env() using initialize_agent (v1 syntax) - Add AgentEnvRunner for episode execution and metrics
- Add babyai_langchain_example.py with usage examples - Add test_models.py with model unit tests - Add test_base.py with wrapper unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces
agentenv-wrapper, a generic package for adapting AgentGym environments into tool-based interfaces suitable for LLM agent frameworks like LangChain.This addresses the feedback on PR WooooDyy#68 (WooooDyy/AgentGym) where @SixPlusSeven67 suggested creating a consistent mapping from existing AgentEnvironments to tools, rather than just demonstrating the MCP server pattern.
Architecture
flowchart TB subgraph Agent["Agent Framework"] LC[LangChain Agent] CA[Custom Agent] end subgraph Wrapper["AgentEnv Wrapper"] BTW[BaseToolWrapper] TEW[ToolEnvironmentWrapper] subgraph Adapters BAW[BabyAIToolWrapper] WSW[WebShopToolWrapper] CW["..."] end subgraph LCI["LangChain Integration"] CLT[create_langchain_tools] CAE[create_agent_for_env] AER[AgentEnvRunner] end end subgraph Servers["AgentGym Environment Servers"] BS[BabyAI Server] WS[WebShop Server] OS["..."] end LC --> CLT CA --> BTW CLT --> BAW CAE --> BAW BAW --> BS TEW --> WS TEW --> OSChanges
Core Components
models.py: Data models (ActionTool, ToolDefinition, ToolResult, EnvState)base.py: BaseToolWrapper abstract class and ToolEnvironmentWrapperadapters/babyai.py: BabyAI-specific adapter with action parsingLangChain Integration
langchain/tools.py: Convert wrapper tools to LangChain toolslangchain/agent.py: create_agent_for_env() using v1 syntax (initialize_agent)AgentEnvRunner: Episode runner with batch support and metricsExamples & Tests
examples/babyai_langchain_example.py: Full usage examplestests/: Unit tests for models and wrappersKey Design Decisions
initialize_agentinstead ofcreate_react_agentfor broader compatibilityUsage Example
Type of Change
Testing
Checklist
Related