6.3 KiB
6.3 KiB
Codex 작업 프롬프트 모음
프롬프트 1 — 구현 메인 프롬프트
You are working inside the local TradingAgents repository.
Goal:
Implement a new LLM provider named codex so TradingAgents can use the local Codex CLI/app-server authenticated with ChatGPT/Codex login instead of an OpenAI API key.
High-level constraints:
- Do NOT build an OpenAI-compatible HTTP proxy.
- Do NOT call raw OAuth endpoints yourself.
- Do NOT depend on Codex dynamicTools for TradingAgents tool execution.
- Keep TradingAgents’ existing LangGraph / ToolNode flow intact.
- The integration must work for both:
- analyst nodes that use
prompt | llm.bind_tools(tools) - non-tool nodes that call
llm.invoke(...)directly
- analyst nodes that use
- Prefer minimal, coherent changes over broad refactors.
- Add tests and documentation.
- No unrelated cleanup.
Architecture to implement:
- Add a new provider
codexintradingagents/llm_clients/factory.py. - Add a
CodexClientimplementing the existing BaseLLMClient contract. - Add a custom LangChain chat model that talks to
codex app-serverover stdio JSONL. - Reuse a long-lived app-server process per model instance, but create a fresh Codex thread per model invocation to avoid context bleed across agents.
- After each invocation,
thread/unsubscribe. - Use
initialize/initializedon startup. - Add a preflight helper that checks:
codexbinary exists- app-server starts
account/readsucceeds- requested models are available from
model/list
- Do not require API keys for the
codexprovider.
Authentication assumptions:
- The supported user path is
codex loginorcodex login --device-auth. - If file-backed auth is used, Codex-managed credentials may be stored in
~/.codex/auth.json. - Do not implement direct OAuth token refresh.
- If auth is missing, fail with a clear actionable message telling the user to run
codex login.
Important implementation choice: Do NOT use app-server dynamic tools. Instead, emulate tool calling at the model boundary with strict structured output:
- For plain non-tool calls, request JSON schema:
{ "answer": string } - For tool-capable calls, request a root
oneOfschema:- final:
{ "mode": "final", "content": string, "tool_calls": [] } - tool batch:
{ "mode": "tool_calls", "content": string, "tool_calls": [ ... ] }
- final:
- For
tool_calls[].items, useoneOfwith one branch per tool so each tool name has its own exact arguments JSON schema. - This is required so TradingAgents’ ToolNode can execute the selected tool calls after receiving an
AIMessage.tool_calls.
Files to add:
tradingagents/llm_clients/codex_client.pytradingagents/llm_clients/codex_chat_model.pytradingagents/llm_clients/codex_app_server.pytradingagents/llm_clients/codex_schema.pytradingagents/llm_clients/codex_message_codec.pytradingagents/llm_clients/codex_preflight.py
Files to modify:
tradingagents/llm_clients/factory.pytradingagents/default_config.pytradingagents/llm_clients/__init__.py- CLI / UI config surfaces if present
- README and/or docs
Model behavior requirements:
- Normalize input from:
str- LangChain
BaseMessagesequences - OpenAI-style dict message sequences
- The custom model must support
bind_tools(). bind_tools()should preserve LangChain semantics by binding tool schemas into_generate(...).- Return
AIMessageobjects. - If tool calls are requested, populate
AIMessage.tool_callswith stable ids likecall_<uuid>.
Safety / hardening requirements:
- Default to a neutral dedicated workspace directory for Codex, not the repo root.
- Add config knobs for:
codex_binarycodex_reasoning_effortcodex_summarycodex_personalitycodex_workspace_dircodex_request_timeoutcodex_max_retriescodex_cleanup_threads
- Document a recommended
.codex/config.tomlwith:approval_policy = "never"sandbox_mode = "read-only"web_search = "disabled"personality = "none"cli_auth_credentials_store = "file"
Testing requirements:
- Unit tests for message normalization.
- Unit tests for output schema construction.
- Unit tests for plain final response parsing.
- Unit tests for tool-call response parsing.
- Unit tests for malformed JSON retry / error reporting.
- Integration smoke test for provider
codex. - Preflight test for missing auth / missing binary.
Acceptance criteria:
llm_provider="codex"works without API keys aftercodex login.- At least one analyst node using
bind_tools()works. - At least one non-tool node using
llm.invoke(...)works. - A minimal smoke run can produce a final report / final decision.
- Documentation explains installation, auth, usage, and limitations.
Implementation style:
- Read the existing code first and align with project style.
- Make the smallest set of clean, composable changes.
- Include comments only where they add real value.
- Avoid speculative abstractions.
- Keep the code production-oriented and debuggable.
Working method:
- Inspect the current LLM client factory and how agents call
bind_tools()vsinvoke(). - Implement the connection layer.
- Implement the chat model.
- Wire the provider.
- Add preflight + docs.
- Add tests.
- Run the relevant tests / smoke checks.
- Summarize exactly what changed and any limitations that remain.
Do the work now.
프롬프트 2 — 검증/수정 프롬프트
Review the codex provider implementation you just added to TradingAgents.
Your job:
- Find correctness bugs, interface mismatches, race conditions, and integration gaps.
- Pay special attention to:
- LangChain
bind_tools()semantics AIMessage.tool_callsstructure- support for
llm.invoke(str),llm.invoke(list[BaseMessage]), andllm.invoke(list[dict]) - app-server request/response matching
- thread cleanup with
thread/unsubscribe - malformed JSON retries
- missing auth / missing binary / missing model diagnostics
- LangChain
- Run or update tests as needed.
- Fix only what is necessary; do not refactor unrelated code.
- Update docs if behavior changed.
Definition of done:
- the provider is internally consistent,
- tests pass,
- smoke run works,
- error messages are actionable,
- no obvious context-bleed or tool-calling contract issues remain.
Return:
- a concise changelog,
- exact files modified,
- exact commands/tests run,
- any remaining known limitations.